-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚠️ (go/v4) decouple webhooks from APIs (Move Webhooks from api/<version>
or api/<group>/<version>
to internal/webhook/<version>
or internal/webhook/<group>/<version>
)
#4150
base: master
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
e607dd5
to
bb55494
Compare
4b5368a
to
86dce22
Compare
8c0d1f8
to
dbde977
Compare
api/<version>
or api/<group>/<version>
to internal/webhook/<version>
or internal/webhook/<group>/<version>
dbde977
to
e382294
Compare
api/<version>
or api/<group>/<version>
to internal/webhook/<version>
or internal/webhook/<group>/<version>
api/<version>
or api/<group>/<version>
to internal/webhook/<version>
or internal/webhook/<group>/<version>
)
e382294
to
fc621e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed only the changes under pkg/ for now. The rest I can review later.
Looks good and seems to work in general.
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go
Show resolved
Hide resolved
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_suitetest.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook_test_template.go
Show resolved
Hide resolved
5e42196
to
67221fc
Compare
HI @fischor Thank you a lot for your review. |
d0f46d2
to
1c7da29
Compare
docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_conversion.go
Outdated
Show resolved
Hide resolved
testdata/project-v4-multigroup/internal/webhook/crew/v1/captain_webhook.go
Show resolved
Hide resolved
1c7da29
to
d6f6c34
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits, rest looks good! (reviewed till legacy-webhook-path.sh
, will come back and review the rest tomorrow).
Thanks @camilamacedo86 for taking care of this!
.../book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook_test.go
Outdated
Show resolved
Hide resolved
"context" | ||
"fmt" | ||
"fmt"`, | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think its taken care by running go fmt
in the end, but the file still has fmt
and context
as imports. So probably we can revert back the first two statements? (
kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go
Lines 21 to 22 in d6f6c34
"context" | |
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, we were using Replace. Now, we are using Insert to be more precise and avoid breaking the code. This allows us to insert the rest of the text starting from a specific point. So, I think that is right, but let me know if I missing something.
pkg/plugins/golang/v4/scaffolds/internal/templates/webhooks/webhook.go
Outdated
Show resolved
Hide resolved
11684fe
to
56c00e3
Compare
Hi @varshaprasad96 and @sbueringer Thank you a lot for your time and amazing review !!! 🥇 |
…sion>` or `api/<group>/<version>` to `internal/webhook/<version>` or `internal/webhook/<group>/<version>` This PR decouples the webhooks from the API, aligning with the recent breaking changes introduced in controller-runtime to ensure that kubebuilder still compatbile with its next release. Webhooks are now scaffolded under `internal/webhook` to comply with the latest standards. **Context:** Controller-runtime deprecated and removed the webhook methods in favor of CustomInterfaces (see [controller-runtime#2641](kubernetes-sigs/controller-runtime#2641)). The motivation for this change is outlined in [controller-runtime#2596](kubernetes-sigs/controller-runtime#2596). See that the current master branch already reflects these changes, using the CustomInterfaces: [kubebuilder#4060](kubernetes-sigs#4060). **Changes:** - Webhooks are now scaffolded in `internal/webhook/<version>` or `internal/webhook/<group>/<version>`. - However, to ensure backwards compatibility, a new `--legacy` flag is introduced. Running `kubebuilder create webhook [options] --legacy` will scaffold webhooks in the legacy location for projects that need to retain the old structure. However, users will still to address the breaking changes in the source code by replacing the old methods by the new CustomInterfaces.
56c00e3
to
982d23d
Compare
(only reviewed the projects in testdata/*) Looks good from my side |
Hi @sbueringer
By looking at the testdata and docs samples you can check the full result of the changes The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always thought it odd that the validation code was in the api :) ✨ 👏
@@ -19,32 +19,35 @@ package v1 | |||
import ( | |||
. "github.com/onsi/ginkgo/v2" | |||
. "github.com/onsi/gomega" | |||
|
|||
batchv1 "tutorial.kubebuilder.io/project/api/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor thing, but often, batchv1 is used when importing Job, and the actual batch/v1 package. Wouldn't it be more normal (in the context of this test) just calling this import "v1" or "apiv1"? It's the project's own API right?
Edit: I see batchv1 is already used extensively, so maybe that should be left for another discussion.
// TODO (user): Add any additional imports if needed | ||
) | ||
|
||
var _ = Describe("CronJob Webhook", func() { | ||
var ( | ||
obj *CronJob | ||
oldObj *CronJob | ||
obj = &batchv1.CronJob{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nit, makes no difference.
obj = &batchv1.CronJob{} | |
obj *batchv1.CronJob |
@@ -188,8 +190,11 @@ const webhookTestCreateDefaultingFragment = `// TODO (user): Add logic for defau | |||
// Example: | |||
// It("Should apply defaults when a required field is empty", func() { | |||
// By("simulating a scenario where defaults should be applied") | |||
// By("simulating a scenario where defaults should be applied") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate line?
@@ -235,20 +240,20 @@ const webhookTestingValidatingTodoFragment = `// TODO (user): Add logic for vali | |||
// It("Should deny creation if a required field is missing", func() { | |||
// By("simulating an invalid creation scenario") | |||
// obj.SomeRequiredField = "" | |||
// Expect(obj.ValidateCreate(ctx)).Error().To(HaveOccurred()) | |||
// Expect(validator.ValidateCreate(ctx, obj)).Error().To(HaveOccurred()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly because of this PR, but this is my previous work on simplifying the gomega assertions. Do you want to replace this with the longer form where err and validations are Expected independently?
@@ -25,16 +25,17 @@ import ( | |||
logf "sigs.k8s.io/controller-runtime/pkg/log" | |||
"sigs.k8s.io/controller-runtime/pkg/webhook" | |||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | |||
|
|||
examplecomv1alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I'm not sure I have the full context, but I would call it "apiv1alpha1" or just "v1alpha1".
// wait for the webhook server to get ready. | ||
dialer := &net.Dialer{Timeout: time.Second} | ||
addrPort := fmt.Sprintf("%s:%s", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort) | ||
Eventually(func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using (g Gomega)
Eventually(func() error { | |
Eventually(func(g gomega) { |
and g.Expect() for error checking.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, mogsie The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This PR decouples the webhooks from the API, aligning with the recent breaking changes introduced in controller-runtime to ensure that kubebuilder still compatbile with its next release. Webhooks are now scaffolded under
internal/webhook
to comply with the latest standards.Context:
Controller-runtime deprecated and removed the webhook methods in favor of CustomInterfaces (see controller-runtime#2641). The motivation for this change is outlined in controller-runtime#2596.
See that the current master branch already reflects these changes, using the CustomInterfaces: kubebuilder#4060.
Changes:
internal/webhook/<version>
orinternal/webhook/<group>/<version>
.--legacy
flag is introduced. Runningkubebuilder create webhook [options] --legacy
will scaffold webhooks in the legacy location for projects that need to retain the old structure. However, users will still to address the breaking changes in the source code by replacing the old methods by the new CustomInterfaces.Example:
(single group / default layout)
$ tree . ... ├── api │ └── v1 │ ├── admiral_types.go │ ├── captain_types.go │ ├── firstmate_types.go │ ├── groupversion_info.go │ └── zz_generated.deepcopy.go ... ├── internal │ ├── controller ... │ └── webhook │ └── v1 │ ├── admiral_webhook.go │ ├── admiral_webhook_test.go │ ├── firstmate_webhook.go │ ├── firstmate_webhook_test.go │ └── webhook_suite_test.go ...
Notes:
If you do not want to change the layout (move your webhooks to internal/webhook then, ) then use the flag
--legacy
and ensure that you upgrade the source code to use the CustomInterfaces as the following examples. However, be aware that thelegacy
path is deprecated and will no longer used in future versions of the Golang Plugins (i.e. go/v5):Closes: #4062