-
Notifications
You must be signed in to change notification settings - Fork 422
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
✨ Allow customizing generated webhook configuration's name #1002
Conversation
Welcome @davidxia! |
Hi @davidxia. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@sbueringer thanks for your tip. How does this look? If this looks good overall, I can write a test for it. Should the test be similar to this? |
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.
tested manually by
GOBIN=(pwd)/bin go install ./cmd/*
- copy the
./bin/controller-gen
executable into a kubebuilder-scaffolded project'sbin/controller-gen-vX.Y.Z
path - remove the
kubectl apply
from the kubebuilder project'sMakefile
'sdeploy
target
case 1: backwards compatibility
-
run
make deploy
and check thatkind: MutatingWebhookConfiguration
andkind: ValidatingWebhookConfiguration
have the same names as before.apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: project-mutating-webhook-configuration
apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: project-validating-webhook-configuration
case 2: specify marker only for MutatingWebhookConfiguration
-
add
// +kubebuilder:webhookconfiguration:name=DEADBEEF,mutating=true
toapi/v1/cronjob_webhook.go
-
run
make deploy
and check thatkind: MutatingWebhookConfiguration
has the following.apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: project-DEADBEEF
instead of
apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: project-mutating-webhook-configuration
-
check that
kind: ValidatingWebhookConfiguration
has the same name as before:project-validating-webhook-configuration
case 2: specify markers for both MutatingWebhookConfiguration and ValidatingWebhookConfiguration
- add
// +kubebuilder:webhookconfiguration:name=DEADBEEF,mutating=true
and// +kubebuilder:webhookconfiguration:name=FOOBAR,mutating=false
toapi/v1/cronjob_webhook.go
- run
make deploy
and check for the following.apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: project-DEADBEEF ... apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: project-FOOBAR
case 3: add multiple kubebuilder:webhookconfiguration:mutating=true
markers
- add both
// +kubebuilder:webhookconfiguration:name=A,mutating=true
and// +kubebuilder:webhookconfiguration:name=a,mutating=true
(in that order) toapi/v1/cronjob_webhook.go
- run
make deploy
and check for the following.controller-gen
sorts and uses the last one.a
sorts to a later position thanA
.apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: project-a
Yup. I think something similar to the test coverage in this PR would be good Oh I think I missed something before. The existing kubebuilder:webhook marker is used to define individual webhooks in the object. While the name is global for the entire MutatingWebhookConfiguration / ValidatingWebhookConfiguration configuration. Might be a bit awkward to define the name of the overall obect on the marker that defines a single element in the webhook array. WDYT about introducing a separate marker called Looking at the issue, the service namespace (& maybe also name?) can be added to the Config struct though (just like Path) |
} else { | ||
// The only possible version in supportedWebhookVersions is v1, | ||
// so use it for all versioned types in this context. | ||
objRaw = &admissionregv1.MutatingWebhookConfiguration{} | ||
objRaw.SetName("mutating-webhook-configuration") | ||
} |
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.
for backwards-compat
} else { | ||
// The only possible version in supportedWebhookVersions is v1, | ||
// so use it for all versioned types in this context. | ||
objRaw = &admissionregv1.ValidatingWebhookConfiguration{} | ||
objRaw.SetName("validating-webhook-configuration") | ||
} |
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.
for backwards-compat
done, PTAL and let me know if that looks good
Good idea. I can make another PR for that once we get something merged for this. |
@joelanford @vincepri do you have time to give this a quick initial review? |
/ok-to-test |
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.
Sorry for the delay, looks good so far!
1006456
to
6d789cf
Compare
6d789cf
to
1d9d9cf
Compare
@sbueringer updated. Lmk if I'm missing anything! |
@davidxia Looks good. PTAL at #1002 (comment) Otherwise happy to merge |
521a807
to
8b7192e
Compare
@sbueringer thanks, but the bot message doesn't say why the commit message is invalid or how to fix. Are there instructions? |
I would just drop everything that contains "closes" or an issue number in the entire commit message |
## example usage ``` ❯ GOBIN=(pwd)/bin go install ./cmd/* ❯ ./bin/controller-gen webhook -w Webhook +kubebuilder:webhook:admissionReviewVersions=<[]string>,failurePolicy=<string>,groups=<[]string>[,matchPolicy=<string>],mutating=<bool>,name=<string>[,path=<string>][,reinvocationPolicy=<string>],resources=<[]string>[,sideEffects=<string>][,timeoutSeconds=<int>][,url=<string>],verbs=<[]string>,versions=<[]string>[,webhookVersions=<[]string>] package specifies how a webhook should be served. +kubebuilder:webhookconfiguration:mutating=<bool>[,name=<string>] package specifies how a webhook should be served. ``` Signed-off-by: David Xia <[email protected]>
8b7192e
to
287a105
Compare
@sbueringer that did the trick. Ready for review and/or merge now. |
Thank you! /lgtm |
LGTM label has been added. Git tree hash: 44d35f3ef0371f7cee392d80cd6259f75063bf7f
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: davidxia, sbueringer 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 contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [sigs.k8s.io/controller-tools](https://github.com/kubernetes-sigs/controller-tools) | `v0.16.2` -> `v0.16.3` | [![age](https://developer.mend.io/api/mc/badges/age/go/sigs.k8s.io%2fcontroller-tools/v0.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/sigs.k8s.io%2fcontroller-tools/v0.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/sigs.k8s.io%2fcontroller-tools/v0.16.2/v0.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/sigs.k8s.io%2fcontroller-tools/v0.16.2/v0.16.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>kubernetes-sigs/controller-tools (sigs.k8s.io/controller-tools)</summary> ### [`v0.16.3`](https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.16.3) [Compare Source](https://github.com/kubernetes-sigs/controller-tools/compare/v0.16.2...v0.16.3) Published binaries on previous v0.16.x releases were reporting an incorrect version. #### What's Changed - 🐛 Allow CLI binaries to set a version by [@​josvazg](https://github.com/josvazg) in [https://github.com/kubernetes-sigs/controller-tools/pull/1049](https://github.com/kubernetes-sigs/controller-tools/pull/1049) - ✨ Allow customizing generated webhook configuration's name by [@​davidxia](https://github.com/davidxia) in [https://github.com/kubernetes-sigs/controller-tools/pull/1002](https://github.com/kubernetes-sigs/controller-tools/pull/1002) #### Dependencies - 🌱 Bump github.com/onsi/gomega from 1.34.1 to 1.34.2 in the all-go-mod-patch-and-minor group by [@​dependabot](https://github.com/dependabot) in [https://github.com/kubernetes-sigs/controller-tools/pull/1047](https://github.com/kubernetes-sigs/controller-tools/pull/1047) - 🌱 Bump tj-actions/changed-files from 45.0.0 to 45.0.1 in the all-github-actions group by [@​dependabot](https://github.com/dependabot) in [https://github.com/kubernetes-sigs/controller-tools/pull/1048](https://github.com/kubernetes-sigs/controller-tools/pull/1048) - 🌱 Bump peter-evans/create-pull-request from 6.1.0 to 7.0.1 in the all-github-actions group by [@​dependabot](https://github.com/dependabot) in [https://github.com/kubernetes-sigs/controller-tools/pull/1052](https://github.com/kubernetes-sigs/controller-tools/pull/1052) #### New Contributors - [@​josvazg](https://github.com/josvazg) made their first contribution in [https://github.com/kubernetes-sigs/controller-tools/pull/1049](https://github.com/kubernetes-sigs/controller-tools/pull/1049) - [@​davidxia](https://github.com/davidxia) made their first contribution in [https://github.com/kubernetes-sigs/controller-tools/pull/1002](https://github.com/kubernetes-sigs/controller-tools/pull/1002) **Full Changelog**: kubernetes-sigs/controller-tools@v0.16.2...v0.16.3 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/registry-operator/registry-operator). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiYXJlYS9kZXBlbmRlbmN5Il19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
example usage
contributes to #865