Skip to content

Commit

Permalink
Merge pull request #1692 from vincepri/fix-md-selector
Browse files Browse the repository at this point in the history
🐛 Fix MachineDeployment Status.Selector not being populated
  • Loading branch information
k8s-ci-robot committed Oct 31, 2019
2 parents bf2cf3d + d101a63 commit 65ee17c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 0 additions & 4 deletions controllers/machinedeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, d *clusterv
return ctrl.Result{}, errors.Errorf("failed validation on MachineDeployment %q label selector, cannot match Machine template labels", d.Name)
}

// Copy label selector to its status counterpart in string format.
// This is necessary for CRDs including scale subresources.
d.Status.Selector = selector.String()

// Cluster might be nil as some providers might not require a cluster object
// for machine management.
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, d.ObjectMeta)
Expand Down
3 changes: 3 additions & 0 deletions controllers/machinedeployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ var _ = Describe("MachineDeployment Reconciler", func() {

return len(machineSets.Items)
}, timeout*5).Should(BeEquivalentTo(0))

// Make sure the deployment selector is being populated.
Expect(deployment.Status.Selector).ToNot(BeEmpty())
})
})

Expand Down
4 changes: 4 additions & 0 deletions controllers/machinedeployment_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,13 @@ func calculateStatus(allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet
unavailableReplicas = 0
}

// Calculate the label selector. We check the error in the MD reconcile function, ignore here.
selector, _ := metav1.LabelSelectorAsSelector(&deployment.Spec.Selector) //nolint

status := clusterv1.MachineDeploymentStatus{
// TODO: Ensure that if we start retrying status updates, we won't pick up a new Generation value.
ObservedGeneration: deployment.Generation,
Selector: selector.String(),
Replicas: mdutil.GetActualReplicaCountForMachineSets(allMSs),
UpdatedReplicas: mdutil.GetActualReplicaCountForMachineSets([]*clusterv1.MachineSet{newMS}),
ReadyReplicas: mdutil.GetReadyReplicaCountForMachineSets(allMSs),
Expand Down

0 comments on commit 65ee17c

Please sign in to comment.