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

✨ (go/v4): improve the webhook tests by adding examples. Also, improve cronjob tutorial to clarify its usage and validate the changes #4130

Merged

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Sep 3, 2024

In this PR we are improving the webhook tests by adding further info and examples for the users. Either we are implementing them further for the cronjob tutorial as an example and to help us to validate and spot issues on related areas when/if we need to change them

Closes: #3454

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 3, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

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 Sep 3, 2024
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 3, 2024
@camilamacedo86 camilamacedo86 changed the title ✨ improve the webhook tests by adding examples. Also, improve cronjob tutorial to clarify its usage. ✨ (go/v4): improve the webhook tests by adding examples. Also, improve cronjob tutorial to clarify its usage and validate the changes Sep 3, 2024
@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Sep 3, 2024

@vsoch , @ashutosh887, @Sajiyah-Salat, @drewwells

Could you please review this PR?

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 3, 2024
@camilamacedo86 camilamacedo86 force-pushed the decouple-webhooks branch 3 times, most recently from ba09ad3 to b4e13b8 Compare September 3, 2024 13:15
In this PR we are improving the webhook tests by adding further
info and examples for the users. Either we are implementing them
further for the cronjob tutorial as an example and to help us to
validate and spot issues on related areas when/if we need to change them
@vsoch
Copy link

vsoch commented Sep 3, 2024

Assuming all the CI passes, this looks very helpful! Thanks @camilamacedo86

Context("When creating or updating CronJob under Validating Webhook", func() {
It("Should deny creation if the name is too long", func() {
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
warnings, err := validator.ValidateCreate(ctx, obj)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can replace this with a single Error matcher:

Expect(validator.ValidateCreate(ctx, obj)).Error().To(MatchError(ContainSubstring("must be no more than 52 characters"))),
	"Expected name validation to fail for a too-long name")

Gomega's error validator both matches the error, and that any other responses (warnings) are zero-valued.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @mogsie

Thank you a lot for your help on those tests !!!
That is amazing !

Since it is just a nit wdyt about we get this one merged and then you push a follow up just to improve this part?
Would you like to contribute with the above enhancement?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. I can follow up on this. Should I make a separate issue for it too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free tor raise the issue, but if you will work on that asap. just push the PR is fine.

@camilamacedo86
Copy link
Member Author

I am moving forward with this because:

  • a) The requestor has already confirmed that it is very helpful.
  • b) After the review, the only feedback we received was a minor nit/enhancement suggestion regarding how to perform the check, which, as agreed, will be addressed in a follow-up.
  • c) We want to implement tests for the webhooks in the sample within the documentation. This will allow us to add further tests and scenarios, which are necessary since we need to decouple the webhooks from the API to fully comply with the latest changes in controller-runtime. You can find more details here: Decouple webhooks from APIs #4062 and here: Changes to webhook.Validator pattern cause version update problems controller-runtime#2596. These tests will help us validate the changes.

@camilamacedo86 camilamacedo86 merged commit defede3 into kubernetes-sigs:master Sep 7, 2024
16 of 18 checks passed
@camilamacedo86 camilamacedo86 deleted the decouple-webhooks branch September 7, 2024 06:46
sarthaksarthak9 pushed a commit to sarthaksarthak9/kubebuilder that referenced this pull request Sep 9, 2024
…e cronjob tutorial to clarify its usage and validate the changes (kubernetes-sigs#4130)

improve the webhook tests by adding examples

In this PR we are improving the webhook tests by adding further
info and examples for the users. Either we are implementing them
further for the cronjob tutorial as an example and to help us to
validate and spot issues on related areas when/if we need to change them
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation request: e2e test with webhook
4 participants