-
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
🐛 Improve handling of patching and updates in MachineSet and MachineDeployment controllers #1380
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: detiber 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 |
@@ -341,7 +342,7 @@ func (r *MachineDeploymentReconciler) syncDeploymentStatus(allMSs []*clusterv1.M | |||
|
|||
patch := client.MergeFrom(d.DeepCopy()) | |||
d.Status = newStatus | |||
return r.Status().Patch(context.Background(), d, patch) | |||
return r.Status().Patch(context.Background(), d.DeepCopy(), patch) |
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.
Would it be better to avoid doing the DeepCopy twice?
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 we can, will add a comment as to why.
@@ -413,7 +414,7 @@ func (r *MachineDeploymentReconciler) scaleMachineSetOperation(ms *clusterv1.Mac | |||
*(ms.Spec.Replicas) = newScale | |||
mdutil.SetReplicasAnnotations(ms, *(deployment.Spec.Replicas), *(deployment.Spec.Replicas)+mdutil.MaxSurge(*deployment)) | |||
|
|||
err = r.Patch(context.Background(), ms, patch) | |||
err = r.Client.Patch(context.Background(), ms, patch) |
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.
Does this need to operate on a copy too?
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.
In this case, I don't think so, because we only update the Metadata of the MachineSet from within the MachineDeployment controller.
@@ -386,9 +386,10 @@ func shouldExcludeMachine(machineSet *clusterv1.MachineSet, machine *clusterv1.M | |||
|
|||
// adoptOrphan sets the MachineSet as a controller OwnerReference to the Machine. | |||
func (r *MachineSetReconciler) adoptOrphan(machineSet *clusterv1.MachineSet, machine *clusterv1.Machine) error { | |||
patch := client.MergeFrom(machine) |
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.
deepcopy?
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.
Not needed in this case, since we only update the Metadata of Machines in the MachineSet controller.
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.
Same comment everywhere else as well, can't we make use of the helper?
e4e3d5e
to
d1b1e81
Compare
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.
LGTM
/assign @ncdc
@@ -111,7 +111,8 @@ func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, d *clusterv | |||
if d.Status.ObservedGeneration < d.Generation { | |||
patch := client.MergeFrom(d.DeepCopy()) | |||
d.Status.ObservedGeneration = d.Generation | |||
if err := r.Client.Status().Patch(ctx, d, patch); err != nil { | |||
// Patch using a deep copy to avoid overwriting any unexpcted Spec/Metadata changes from the returned result |
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.
// Patch using a deep copy to avoid overwriting any unexpcted Spec/Metadata changes from the returned result | |
// Patch using a deep copy to avoid overwriting any unexpected Spec/Metadata changes from the returned result |
d1b1e81
to
7139c0d
Compare
…loyment controllers
7139c0d
to
feeea0c
Compare
/lgtm |
What this PR does / why we need it:
Improves handling of patch and update semantics used by MachineSet and MachineDeployment controllers
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 #1349