Skip to content
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

Merged
merged 5 commits into from
Jun 12, 2023

Conversation

hectorj2f
Copy link
Contributor

@hectorj2f hectorj2f commented May 14, 2023

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

Configure controller options and other settings when generating webhook configurations.

Docs


@knative-prow knative-prow bot added the kind/bug Categorizes issue or PR as related to a bug. label May 14, 2023
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 14, 2023
@knative-prow knative-prow bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 14, 2023
@knative-prow
Copy link

knative-prow bot commented May 14, 2023

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@knative-prow knative-prow bot requested review from carlisia and skonto May 14, 2023 10:02
@hectorj2f hectorj2f changed the title Defaulting options Defaulting Controller options for all kind of webhooks May 14, 2023
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 14, 2023
@dprotaso
Copy link
Member

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 17, 2023
Copy link
Member

@dprotaso dprotaso left a 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

Comment on lines 56 to 77
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
}
Copy link
Member

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

Copy link
Contributor Author

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.

Comment on lines 51 to 55
func WithKinds(kinds map[schema.GroupKind]GroupKindConversion) OptionFunc {
return func(o *options) {
o.kinds = kinds
}
}
Copy link
Member

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.

Copy link
Contributor Author

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.

@hectorj2f
Copy link
Contributor Author

Curious why do you need multiple defaulting webhooks?

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.

? Since you're constructing these webhooks programmatically you could collapse all the types being defaulted into a single webhook

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.

dprotaso and others added 4 commits June 4, 2023 23:25
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 4, 2023
@hectorj2f
Copy link
Contributor Author

@dprotaso @pierDipi I've changed the code to be independent for each webhook type due to the potential breaking issues that other changes could cause.

webhook/resourcesemantics/validation/controller.go Outdated Show resolved Hide resolved
Comment on lines +81 to +85
opts := &options{}

for _, f := range optsFunc {
f(opts)
}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link

codecov bot commented Jun 5, 2023

Codecov Report

Patch coverage: 96.57% and project coverage change: +0.21 🎉

Comparison is base (5671699) 81.80% compared to head (d2f9e8c) 82.01%.

❗ Current head d2f9e8c differs from pull request most recent head fbc32b0. Consider uploading reports for the commit fbc32b0 to get more accurate results

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     
Impacted Files Coverage Δ
webhook/webhook.go 78.66% <ø> (ø)
webhook/resourcesemantics/validation/controller.go 92.59% <89.47%> (-3.16%) ⬇️
webhook/resourcesemantics/conversion/controller.go 89.09% <95.83%> (+4.88%) ⬆️
webhook/resourcesemantics/conversion/options.go 100.00% <100.00%> (ø)
webhook/resourcesemantics/defaulting/controller.go 97.10% <100.00%> (+1.26%) ⬆️
webhook/resourcesemantics/defaulting/options.go 100.00% <100.00%> (ø)
webhook/resourcesemantics/validation/options.go 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@skonto
Copy link
Contributor

skonto commented Jun 7, 2023

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>
@hectorj2f hectorj2f requested a review from pierDipi June 9, 2023 10:45
@hectorj2f
Copy link
Contributor Author

@pierDipi Could you have another look at my changes? Thanks in advance.

Copy link
Member

@pierDipi pierDipi left a 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

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2023
@knative-prow
Copy link

knative-prow bot commented Jun 12, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 12, 2023
@knative-prow knative-prow bot merged commit 15605c7 into knative:main Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants