-
Notifications
You must be signed in to change notification settings - Fork 330
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
Defaulting Controller options for all kind of webhooks #2738
Conversation
Hi @hectorj2f. Thanks for your PR. I'm waiting for a knative 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/test-infra repository. |
c05e752
to
35ca933
Compare
35ca933
to
e74332d
Compare
/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.
Curious why do you need multiple defaulting webhooks?
Since you're constructing these webhooks programmatically you could collapse all the types being defaulted into a single webhook
type GroupKindConversion struct { | ||
// DefinitionName specifies the CustomResourceDefinition that should | ||
// be reconciled with by the controller. | ||
// | ||
// The conversion webhook configuration will be updated | ||
// when the CA bundle changes | ||
DefinitionName string | ||
|
||
// HubVersion specifies which version of the CustomResource supports | ||
// conversions to and from all types | ||
// | ||
// It is expected that the Zygotes map contains an entry for the | ||
// specified HubVersion | ||
HubVersion string | ||
|
||
// Zygotes contains a map of version strings (ie. v1, v2) to empty | ||
// ConvertibleObject objects | ||
// | ||
// During a conversion request these zygotes will be deep copied | ||
// and manipulated using the apis.Convertible interface | ||
Zygotes map[string]ConvertibleObject | ||
} |
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.
Deleting these types is unfortunately a breaking change
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.
Yes, it isn't nice. We'll need to keep this type untouched.
func WithKinds(kinds map[schema.GroupKind]GroupKindConversion) OptionFunc { | ||
return func(o *options) { | ||
o.kinds = kinds | ||
} | ||
} |
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 don't know if I like this approach. Essentially we're creating a common set of options but they don't work with all webhook types.
ie. WithKinds
passed to a defaulting webhook is really a noop and not semantically valid. Ideally we don't want downstream users doing 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.
My main goal was to simplify the code here. As an alternative, we could have a common interface with the shared options, and re-implement it on every single webhook with their specific options.
Sorry, I am not sure I understand what you mean here. We have to abstract the way the controllers are initialized as each one has its own logic. The intention of this PR comes from reusing your initial approach across all the different controllers instead of adding similar code to each one of them. @pierDipi Based on the comments, I am not sure we want to reuse this approach #2420 to solve the problem you and myself found in #2731.
Indeed, if we decide to do that, I'd prefer to make that change as part of a different PR to simplify these changes in a manageable way. |
In my case, I wanted to have webhooks with different selectors, you can see it here:
|
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
e74332d
to
d2f9e8c
Compare
opts := &options{} | ||
|
||
for _, f := range optsFunc { | ||
f(opts) | ||
} |
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.
Should we validate provided options?
what happens if I don't call WithWrapContext
and so no opts.wc
is provided?
Same questions on other kinds of webhooks.
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'd prefer we make this change in a different PR.
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.
Wondering if we could simply make NewController to be private newController(
here as a solution until we put in place the validation ?
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2738 +/- ##
==========================================
+ Coverage 81.80% 82.01% +0.21%
==========================================
Files 163 166 +3
Lines 10035 10161 +126
==========================================
+ Hits 8209 8334 +125
- Misses 1580 1582 +2
+ Partials 246 245 -1
☔ View full report in Codecov by Sentry. |
It would be nice to get this in, I hit the same issue while merging the webhooks at the Serving side due to the lease conflict (queue name), I wish I had checked earlier as I spent some time debugging :) |
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
@pierDipi Could you have another look at my changes? Thanks in advance. |
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.
Thanks @hectorj2f !
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hectorj2f, pierDipi 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 |
Changes
In order to unify a bug fix for #2731 and #2420 reusing the initial work from @dprotaso (https://github.com/knative/pkg/compare/main...dprotaso:defaulting-options?body=&expand=1&title=functional+options) and @pierDipi.
I added support to define the controllerOptions and other configurations settings for the webhooks, so the QueueName and other values are configurable now.
/kind bug
Fixes #
Release Note
Docs