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

🐛 Improve handling of patching and updates in MachineSet and MachineDeployment controllers #1380

Merged
merged 1 commit into from
Sep 9, 2019

Conversation

detiber
Copy link
Member

@detiber detiber commented Sep 5, 2019

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

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 5, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 5, 2019
controllers/cluster_controller_phases.go Outdated Show resolved Hide resolved
controllers/machinedeployment_controller.go Outdated Show resolved Hide resolved
@@ -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)
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

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?

Copy link
Member Author

@detiber detiber Sep 5, 2019

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

deepcopy?

Copy link
Member Author

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.

Copy link
Member

@vincepri vincepri left a 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?

controllers/machinedeployment_controller.go Outdated Show resolved Hide resolved
@detiber detiber force-pushed the ImprovePatching branch 2 times, most recently from e4e3d5e to d1b1e81 Compare September 9, 2019 18:49
@detiber detiber changed the title [WIP] 🐛 Improve handling of patching and updates in MachineSet and MachineDeployment controllers 🐛 Improve handling of patching and updates in MachineSet and MachineDeployment controllers Sep 9, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2019
Copy link
Member

@vincepri vincepri left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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

@ncdc
Copy link
Contributor

ncdc commented Sep 9, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 9, 2019
@k8s-ci-robot k8s-ci-robot merged commit af25429 into kubernetes-sigs:master Sep 9, 2019
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deleting a Cluster does not delete related MachineDeployments
4 participants