Skip to content

Commit d8a3aaf

Browse files
authored
Merge pull request #9262 from muraee/propogate-ms-condition-to-md
✨ Add MachineSetReady condition to MachineDeployment
2 parents 602f245 + 4bc8a1f commit d8a3aaf

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

api/v1beta1/condition_consts.go

+8
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ const (
233233
// machines required (i.e. Spec.Replicas-MaxUnavailable when MachineDeploymentStrategyType = RollingUpdate) are up and running for at least minReadySeconds.
234234
MachineDeploymentAvailableCondition ConditionType = "Available"
235235

236+
// MachineSetReadyCondition reports a summary of current status of the MachineSet owned by the MachineDeployment.
237+
MachineSetReadyCondition ConditionType = "MachineSetReady"
238+
239+
// WaitingForMachineSetFallbackReason (Severity=Info) documents a MachineDeployment waiting for the underlying MachineSet
240+
// to be available.
241+
// NOTE: This reason is used only as a fallback when the MachineSet object is not reporting its own ready condition.
242+
WaitingForMachineSetFallbackReason = "WaitingForMachineSet"
243+
236244
// WaitingForAvailableMachinesReason (Severity=Warning) reflects the fact that the required minimum number of machines for a machinedeployment are not available.
237245
WaitingForAvailableMachinesReason = "WaitingForAvailableMachines"
238246
)

internal/controllers/machinedeployment/machinedeployment_sync.go

+11
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,17 @@ func (r *Reconciler) syncDeploymentStatus(allMSs []*clusterv1.MachineSet, newMS
499499
} else {
500500
conditions.MarkFalse(md, clusterv1.MachineDeploymentAvailableCondition, clusterv1.WaitingForAvailableMachinesReason, clusterv1.ConditionSeverityWarning, "Minimum availability requires %d replicas, current %d available", minReplicasNeeded, md.Status.AvailableReplicas)
501501
}
502+
503+
if newMS != nil {
504+
// Report a summary of current status of the MachineSet object owned by this MachineDeployment.
505+
conditions.SetMirror(md, clusterv1.MachineSetReadyCondition,
506+
newMS,
507+
conditions.WithFallbackValue(false, clusterv1.WaitingForMachineSetFallbackReason, clusterv1.ConditionSeverityInfo, ""),
508+
)
509+
} else {
510+
conditions.MarkFalse(md, clusterv1.MachineSetReadyCondition, clusterv1.WaitingForMachineSetFallbackReason, clusterv1.ConditionSeverityInfo, "MachineSet not found")
511+
}
512+
502513
return nil
503514
}
504515

internal/controllers/machinedeployment/machinedeployment_sync_test.go

+39-3
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func newTestMachineDeployment(pds *int32, replicas, statusReplicas, updatedRepli
430430
}
431431

432432
// helper to create MS with given availableReplicas.
433-
func newTestMachinesetWithReplicas(name string, specReplicas, statusReplicas, availableReplicas int32) *clusterv1.MachineSet {
433+
func newTestMachinesetWithReplicas(name string, specReplicas, statusReplicas, availableReplicas int32, conditions clusterv1.Conditions) *clusterv1.MachineSet {
434434
return &clusterv1.MachineSet{
435435
ObjectMeta: metav1.ObjectMeta{
436436
Name: name,
@@ -443,6 +443,7 @@ func newTestMachinesetWithReplicas(name string, specReplicas, statusReplicas, av
443443
Status: clusterv1.MachineSetStatus{
444444
AvailableReplicas: availableReplicas,
445445
Replicas: statusReplicas,
446+
Conditions: conditions,
446447
},
447448
}
448449
}
@@ -460,7 +461,7 @@ func TestSyncDeploymentStatus(t *testing.T) {
460461
name: "Deployment not available: MachineDeploymentAvailableCondition should exist and be false",
461462
d: newTestMachineDeployment(&pds, 3, 2, 2, 2, clusterv1.Conditions{}),
462463
oldMachineSets: []*clusterv1.MachineSet{},
463-
newMachineSet: newTestMachinesetWithReplicas("foo", 3, 2, 2),
464+
newMachineSet: newTestMachinesetWithReplicas("foo", 3, 2, 2, clusterv1.Conditions{}),
464465
expectedConditions: []*clusterv1.Condition{
465466
{
466467
Type: clusterv1.MachineDeploymentAvailableCondition,
@@ -474,14 +475,49 @@ func TestSyncDeploymentStatus(t *testing.T) {
474475
name: "Deployment Available: MachineDeploymentAvailableCondition should exist and be true",
475476
d: newTestMachineDeployment(&pds, 3, 3, 3, 3, clusterv1.Conditions{}),
476477
oldMachineSets: []*clusterv1.MachineSet{},
477-
newMachineSet: newTestMachinesetWithReplicas("foo", 3, 3, 3),
478+
newMachineSet: newTestMachinesetWithReplicas("foo", 3, 3, 3, clusterv1.Conditions{}),
478479
expectedConditions: []*clusterv1.Condition{
479480
{
480481
Type: clusterv1.MachineDeploymentAvailableCondition,
481482
Status: corev1.ConditionTrue,
482483
},
483484
},
484485
},
486+
{
487+
name: "MachineSet exist: MachineSetReadyCondition should exist and mirror MachineSet Ready condition",
488+
d: newTestMachineDeployment(&pds, 3, 3, 3, 3, clusterv1.Conditions{}),
489+
oldMachineSets: []*clusterv1.MachineSet{},
490+
newMachineSet: newTestMachinesetWithReplicas("foo", 3, 3, 3, clusterv1.Conditions{
491+
{
492+
Type: clusterv1.ReadyCondition,
493+
Status: corev1.ConditionFalse,
494+
Reason: "TestErrorResaon",
495+
Message: "test error messsage",
496+
},
497+
}),
498+
expectedConditions: []*clusterv1.Condition{
499+
{
500+
Type: clusterv1.MachineSetReadyCondition,
501+
Status: corev1.ConditionFalse,
502+
Reason: "TestErrorResaon",
503+
Message: "test error messsage",
504+
},
505+
},
506+
},
507+
{
508+
name: "MachineSet doesn't exist: MachineSetReadyCondition should exist and be false",
509+
d: newTestMachineDeployment(&pds, 3, 3, 3, 3, clusterv1.Conditions{}),
510+
oldMachineSets: []*clusterv1.MachineSet{},
511+
newMachineSet: nil,
512+
expectedConditions: []*clusterv1.Condition{
513+
{
514+
Type: clusterv1.MachineSetReadyCondition,
515+
Status: corev1.ConditionFalse,
516+
Severity: clusterv1.ConditionSeverityInfo,
517+
Reason: clusterv1.WaitingForMachineSetFallbackReason,
518+
},
519+
},
520+
},
485521
}
486522

487523
for _, test := range tests {

0 commit comments

Comments
 (0)