Skip to content

Commit 65ee17c

Browse files
authored
Merge pull request #1692 from vincepri/fix-md-selector
🐛 Fix MachineDeployment Status.Selector not being populated
2 parents bf2cf3d + d101a63 commit 65ee17c

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

controllers/machinedeployment_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ func (r *MachineDeploymentReconciler) reconcile(ctx context.Context, d *clusterv
132132
return ctrl.Result{}, errors.Errorf("failed validation on MachineDeployment %q label selector, cannot match Machine template labels", d.Name)
133133
}
134134

135-
// Copy label selector to its status counterpart in string format.
136-
// This is necessary for CRDs including scale subresources.
137-
d.Status.Selector = selector.String()
138-
139135
// Cluster might be nil as some providers might not require a cluster object
140136
// for machine management.
141137
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, d.ObjectMeta)

controllers/machinedeployment_controller_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ var _ = Describe("MachineDeployment Reconciler", func() {
296296

297297
return len(machineSets.Items)
298298
}, timeout*5).Should(BeEquivalentTo(0))
299+
300+
// Make sure the deployment selector is being populated.
301+
Expect(deployment.Status.Selector).ToNot(BeEmpty())
299302
})
300303
})
301304

controllers/machinedeployment_sync.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,13 @@ func calculateStatus(allMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet
358358
unavailableReplicas = 0
359359
}
360360

361+
// Calculate the label selector. We check the error in the MD reconcile function, ignore here.
362+
selector, _ := metav1.LabelSelectorAsSelector(&deployment.Spec.Selector) //nolint
363+
361364
status := clusterv1.MachineDeploymentStatus{
362365
// TODO: Ensure that if we start retrying status updates, we won't pick up a new Generation value.
363366
ObservedGeneration: deployment.Generation,
367+
Selector: selector.String(),
364368
Replicas: mdutil.GetActualReplicaCountForMachineSets(allMSs),
365369
UpdatedReplicas: mdutil.GetActualReplicaCountForMachineSets([]*clusterv1.MachineSet{newMS}),
366370
ReadyReplicas: mdutil.GetReadyReplicaCountForMachineSets(allMSs),

0 commit comments

Comments
 (0)