Skip to content

🐛 Fix custom path for webhooks conflict #3102

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

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

damsien
Copy link
Contributor

@damsien damsien commented Feb 5, 2025

Following this PR #2998. I implemented the custom path for webhooks considering that it will be used by either only the validating or the defaulting. However, the user can actually use the both of them on the same webhook manager.

Until now, when the user was using .WithDefaulter(&TestCustomDefaulter{}), .WithValidator(&TestCustomValidator{}) and .WithCustomPath(customPath) at the same time, an endless loop was launched by constantly calling the other webhook. This bug is caused because they are both register at the same path.

This is the reason why I made this PR. I split the .WithCustomPath() function into two functions .WithDefaultingCustomPath() and .WithValidatingCustomPath() in order to be used in this way:

WebhookManagedBy(mgr).
	For(&TestDefaulter{}).
	WithDefaulter(&TestCustomDefaulter{}).
	WithValidator(&TestCustomValidator{}).
	WithDefaultingCustomPath(defaultingCustomPath).
	WithValidatingCustomPath(validatingCustomPath).
	Complete()

Also, I added two tests:

  1. One that tests the example above.
  2. And I take advantage of making this PR to add a second one that tests the usage of WithDefaulter() and WithValidator() at the same time (without the custom path implementation) because there were no test about this specific configuration before.

@k8s-ci-robot k8s-ci-robot requested a review from FillZpp February 5, 2025 20:07
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 5, 2025
@k8s-ci-robot k8s-ci-robot requested a review from inteon February 5, 2025 20:07
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @damsien. 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 /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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 5, 2025
@damsien
Copy link
Contributor Author

damsien commented Feb 5, 2025

Hello @alvaroaleman , what do you think about this one? I know that it can potentially be a breaking change because we are renaming a function that already exists. I am not sure about the upgrade process that must be done (is it simply a ⚠️ breaking change warning in the release note or a more elaborated procedure?).

Also, I wanted to let you know that it is not yet implemented in the kubebuilder project. I am currently working on the implementation into kubebuilder but I first want to ensure that this bug has been fixed before implementing it.

@@ -95,9 +96,15 @@ func (blder *WebhookBuilder) RecoverPanic(recoverPanic bool) *WebhookBuilder {
return blder
}

// WithCustomPath overrides the webhook's default path by the customPath
func (blder *WebhookBuilder) WithCustomPath(customPath string) *WebhookBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming this makes this PR a breaking change for everyone, we should not do that. The two main alternatives I can think of are:

  1. Only one of WithCustomDefaulter/WithCustomValidator may be set when using WithCustomPath, otherwise we error out
  2. We use indexing, i.E. when both are set, there must also be two WithCustomPath calls and the first gets the first/the second the second

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Alvaro,

What about this one:

We keep the WithCustomPath(), WithDefaultingCustomPath() and WithValidatingCustomPath() functions. If the developer uses the WithCustomPath() function, then only one of the WithCustomDefaulter() or WithCustomValidator() should be set, otherwise the developer should use the specific custom path functions.

Maybe it is not a good idea because we have multiple function accomplishing the same purpose. Waiting for you thoughts about it.

Copy link
Member

@sbueringer sbueringer Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

  1. Enforce only one of WithCustomDefaulter/WithCustomValidator may be set when using WithCustomPath, otherwise we error out
  2. Deprecate WithCustomPath
  3. Add new options to WithDefaulter / WithValidator that allows to set the path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damsien I meant something slightly diferently :)

Instead of having additional WithValidatingCustomPath & WithDefaultingCustomPath funcs I was suggesting to add options to the existing WithDefaulter / WithValidator functions to set the path (similar to the existing option that already exists for the WithDefaulter funct)

Copy link
Member

@sbueringer sbueringer Mar 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay nevermind. Just noticed that DefaulterOptions are also passed down to WithCustomDefaulter and there the custom path wouldn't make any sense

@damsien
Copy link
Contributor Author

damsien commented Mar 1, 2025

Hello @alvaroaleman @sbueringer,

Following our conversation, I add some pre-checks:

  1. Enforce only one of WithCustomDefaulter()/WithCustomValidator() when using WithCustomPath()
  2. Enforce only one of WithDefaultingCustomPath() or WithCustomPath()
  3. Enforce only one of WithValidatingCustomPath() or WithCustomPath()

If at least one of these checks are not good, then we error out when calling Complete().

Also, I added a Deprecated comment on top of the WithCustomPath() function.

What do you think? (I'll squash all my commits when we'll validate the merge)

@sbueringer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Mar 16, 2025
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 16, 2025
@damsien
Copy link
Contributor Author

damsien commented Mar 16, 2025

Thanks @sbueringer !
I renamed the functions and variables (validating -> validator & defaulting -> defaulter). Did some changes to pass the lint check.

@sbueringer
Copy link
Member

Thank you!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 17, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: b286157ec763827d7020ed7d1dedfcb140f5b958

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: damsien, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 17, 2025
@sbueringer sbueringer removed the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 17, 2025
@k8s-ci-robot k8s-ci-robot merged commit 4288b1f into kubernetes-sigs:main Mar 17, 2025
9 of 10 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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.

4 participants