-
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
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
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 !!! 🥇 |
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 :) ✨ 👏
docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go
Show resolved
Hide resolved
docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go
Outdated
Show resolved
Hide resolved
@@ -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?
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.
If you see areas for improvement, please feel free to raise a PR. We can definitely make further enhancements in a follow-up.
testdata/project-v4-multigroup/internal/webhook/example.com/v1alpha1/memcached_webhook.go
Show resolved
Hide resolved
// 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.
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 think we can update it in a follow-up once all the checks and adjustments for this test are made according to your suggestions. We will need to revise the entire content and tests related to this matter. What do you think? Could this be included as part of the issue you’re currently working on?
982d23d
to
755429a
Compare
755429a
to
0e472c3
Compare
…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.
0e472c3
to
0abd1a8
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.
/lgtm
I think it's ready to be merged too! Thank you!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, mogsie, varshaprasad96 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