-
Notifications
You must be signed in to change notification settings - Fork 430
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
feat: validate AzureCluster update for location property #522
feat: validate AzureCluster update for location property #522
Conversation
@jackfrancis: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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. |
Welcome @jackfrancis! |
Hi @jackfrancis. 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 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jackfrancis The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@jackfrancis please add a release note. |
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 @jackfrancis for your PR 👍
you still need to update the webhook config, check the machine webhook for an example
apiVersion: admissionregistration.k8s.io/v1beta1 |
} | ||
} | ||
|
||
func createAzureCluster(t *testing.T, location string) *AzureCluster { |
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.
the input t
is not used
}, | ||
} | ||
for _, tc := range tests { | ||
tc := tc |
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 think this is needed
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.
You are correct, it is not needed because t.Run
is running synchronously. I usually advocate for this style as it's often missed when someone goes to make a test parallel and then runs into the pernicious issue of closure capture.
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.
Added the parallel invocation to settle the debate :)
t.Run(tc.name, func(t *testing.T) { | ||
err := tc.cluster.ValidateUpdate(tc.updated) | ||
if tc.wantErr { | ||
g.Expect(err).To(HaveOccurred()) |
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.
can we also check that the returned error is as expected
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 would recommend to separate the validation library from the webhook, and use the library in the webhook instead.
bae65c5
to
d65fdfb
Compare
/ok-to-test |
@jackfrancis you need to run from the test log above: Also did you see @serbrech's comment above? See |
return fmt.Errorf("update object is not a AzureCluster type") | ||
} | ||
|
||
if azureCluster.Spec.Location != r.Spec.Location { |
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.
@CecileRobertMichon @serbrech do we really want to create a re-usable function to validate that two strings aren't equal?
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 think @serbrech's point is that the _webhook file shouldn't contain the actual logic for validation but instead each object should have its own _validation file with functions that can each be unit tested separately. Right now it might be just a string comparison because you only setup the initial skeleton for Cluster update validation but as we add more validations the logic will become more complex. Might as well start things the right way so others can be guided to add further validations in the right place. See how ValidateCronJob
is implemented here for an example.
@serbrech please correct me if I'm wrong.
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.
+1 to what Cecile said, just to setup the structure for future validations
@jackfrancis: PR needs rebase. 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. |
@jackfrancis a lot of this surface area has changed and conflicts with #604, I think the easiest way might be to close this PR and start fresh. The immutable fields can be validated as part of https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/api/v1alpha3/azurecluster_validation.go#L37 by passing in the old AzureCluster object as part of validateUpdate(). Feel free to unassign if you don't think you'll have time to get to this in the near term. |
Happy to start over! |
What this PR does / why we need it:
This PR adds CRUD validations as webhooks to the AzureCluster resource type.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Related to #497
Special notes for your reviewer:
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
Release note: