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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡Add checks in ValidCreate and ValidUpdate in hbmmt webhook #1319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yrs147
Copy link
Contributor

@yrs147 yrs147 commented May 22, 2024

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1165

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squash commits
  • include documentation
  • add unit tests

@yrs147 yrs147 changed the title 馃尡(WIP)Add checks in ValidCreate and ValidUpdate in hbmmt webhook 馃尡Add checks in ValidCreate and ValidUpdate in hbmmt webhook May 22, 2024
Copy link
Contributor

@janiskemper janiskemper left a comment

Choose a reason for hiding this comment

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

looks good so far. You can see in the examples I mentioned in the issue how they did it. You can maybe find an approach with a utility function that allows you to not copy paste the code in the two places

@yrs147 yrs147 requested a review from janiskemper May 22, 2024 12:00
api/v1beta1/hcloudmachine_validation.go Outdated Show resolved Hide resolved
api/v1beta1/hcloudmachinetemplate_webhook.go Outdated Show resolved Hide resolved
@yrs147 yrs147 requested a review from janiskemper May 23, 2024 07:28
Copy link
Contributor

@janiskemper janiskemper left a comment

Choose a reason for hiding this comment

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

cool! Small thing about consistency: Can you name everything you added with "HCloud"? Capital "C"? We usually do that

@yrs147 yrs147 requested a review from janiskemper May 23, 2024 09:26
api/v1beta1/hcloudmachine_webhook.go Outdated Show resolved Hide resolved
@yrs147
Copy link
Contributor Author

yrs147 commented May 23, 2024

removed it

@yrs147 yrs147 requested a review from janiskemper May 23, 2024 10:43
Copy link
Contributor

@janiskemper janiskemper left a comment

Choose a reason for hiding this comment

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

looks good from my side! Have you already tested the new webhooks for template objects?

You can also write unit tests similar to

var _ = Describe("HCloudMachine validation", func() {
and the respective tests in hetznerbaremetalmachine controller

@yrs147 yrs147 force-pushed the yrs/webook-provider-machine-template branch from 241c620 to 1e32559 Compare May 27, 2024 09:50
@yrs147 yrs147 requested a review from janiskemper June 4, 2024 12:48
@yrs147 yrs147 marked this pull request as ready for review June 6, 2024 15:07
@syself-bot syself-bot bot added area/code Changes made in the code directory area/api Changes made in the api directory labels Jun 6, 2024
Copy link
Contributor

@janiskemper janiskemper left a comment

Choose a reason for hiding this comment

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

lgtm. Looks nice. Thanks! You can squash! make sure to choose a good commit title AND message where you describe what you do

Added validation checks for hbmm , hbmmt , hcloudmachine and hcloud
machinetemplate webhooks . Also added the unit tests for the same
@yrs147 yrs147 force-pushed the yrs/webook-provider-machine-template branch from 25ccb55 to 180a275 Compare June 7, 2024 06:13
@syself-bot syself-bot bot added the size/XL Denotes a PR that changes 800-2000 lines, ignoring generated files. label Jun 7, 2024
@yrs147 yrs147 requested a review from janiskemper June 17, 2024 09:38
})
It("should validate update", func() {
newhbmmt := hbmmt.DeepCopy()
warnings, err := hbmmtwebhook.ValidateUpdate(ctx, oldhbmmt, newhbmmt)
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 this test doesn't make sense. oldhbmmt is always nil!

@@ -247,5 +247,59 @@ var _ = Describe("HCloudMachineTemplateReconciler", func() {
}, timeout, time.Second).Should(BeTrue())
})
})
Context("HCloudMachineTemplate Webhook Validation", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

the tests here should work with envtest. This means that you create an object and depending on whether you want it to succeed or fail, you expect an error on creation or not. Same with update. For update, you need to first create it, then fetch it, then update it, and expect either an error or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Changes made in the api directory area/code Changes made in the code directory size/XL Denotes a PR that changes 800-2000 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add webhooks for ProviderMachineTemplate objects
2 participants