-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Validate machineset before reconciling #669
Validate machineset before reconciling #669
Conversation
It would be great to have a unit test for this behavioural change. |
172dd77
to
b886317
Compare
b886317
to
0e6bdbe
Compare
/test pull-cluster-api-test |
0e6bdbe
to
093a79d
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ingvagabund If they are not already assigned, you can assign the PR to them by writing 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 |
2b2ce48
to
35d9925
Compare
b4b9985
to
8ab12f5
Compare
6fa6a53
to
d529f03
Compare
/test pull-cluster-api-test |
d529f03
to
7ee9873
Compare
7ee9873
to
0367fcb
Compare
Even thought the MachineSet type implements Validate() function, it's not called by default. The validation function is responsible for making sure every machine set matchLabels selector is matched with machine template labels. Given the validation is not performed by default, it is possible to create an invalid machineset that causes the machineset controller to start creating machine object one by one without any upper bound. Causing the machine controller to launch as many instances as there is machine objects.
0367fcb
to
b209d7b
Compare
/retest |
@@ -150,6 +150,13 @@ func (r *ReconcileMachineSet) Reconcile(request reconcile.Request) (reconcile.Re | |||
} | |||
|
|||
klog.V(4).Infof("Reconcile machineset %v", machineSet.Name) | |||
|
|||
if errList := machineSet.Validate(); len(errList) > 0 { |
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.
we could consider to run and Admission Webhook for this and similar features. This is better than we have today though
expectedRequest: reconcile.Request{NamespacedName: types.NamespacedName{Name: "invalidfoo", Namespace: "default"}}, | ||
verifyFnc: func() { | ||
// expecting machineset validation error | ||
if _, err := r.Reconcile(reconcile.Request{ |
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 could also validate reconcile.Result{}
here
overall lgtm |
Remove vestigial tokens package
Even thought the MachineSet type implements Validate() function,
it's not called by default. The validation function is responsible
for making sure every machine set matchLabels selector is matched with
machine template labels. Given the validation is not performed by default,
it is possible to create an invalid machineset that causes the machineset
controller to start creating machine object one by one without any upper
bound. Causing the machine controller to launch as many instances as
there is machine objects.
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 #
Special notes for your reviewer:
How to reproduce it? Deploy a machineset with at least one replica. Then run
kubectl edit
to change the machinesetmatchLabels
the way it does not match machine template labels.Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
Release note: