Skip to content

Commit 2016b0d

Browse files
fabriziopandinimarek-veber
authored andcommitted
Refine MachineDeployment v1beta2 available condition
1 parent bcbcdc2 commit 2016b0d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

internal/controllers/machinedeployment/machinedeployment_status.go

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func setAvailableCondition(_ context.Context, machineDeployment *clusterv1.Machi
141141
if machineDeployment.Spec.Strategy != nil && mdutil.IsRollingUpdate(machineDeployment) && machineDeployment.Spec.Strategy.RollingUpdate != nil {
142142
message += fmt.Sprintf(" (spec.strategy.rollout.maxUnavailable is %s, spec.replicas is %d)", machineDeployment.Spec.Strategy.RollingUpdate.MaxUnavailable, *machineDeployment.Spec.Replicas)
143143
}
144+
145+
if !machineDeployment.DeletionTimestamp.IsZero() {
146+
message = "Deletion in progress"
147+
}
144148
v1beta2conditions.Set(machineDeployment, metav1.Condition{
145149
Type: clusterv1.MachineDeploymentAvailableV1Beta2Condition,
146150
Status: metav1.ConditionFalse,

internal/controllers/machinedeployment/machinedeployment_status_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,32 @@ func Test_setAvailableCondition(t *testing.T) {
191191
Message: "3 available replicas, at least 4 required (spec.strategy.rollout.maxUnavailable is 1, spec.replicas is 5)",
192192
},
193193
},
194+
{
195+
name: "When deleting, don't show required replicas",
196+
machineDeployment: &clusterv1.MachineDeployment{
197+
ObjectMeta: metav1.ObjectMeta{
198+
DeletionTimestamp: ptr.To(metav1.Now()),
199+
},
200+
Spec: clusterv1.MachineDeploymentSpec{
201+
Replicas: ptr.To(int32(5)),
202+
Strategy: &clusterv1.MachineDeploymentStrategy{
203+
Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
204+
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
205+
MaxSurge: ptr.To(intstr.FromInt32(1)),
206+
MaxUnavailable: ptr.To(intstr.FromInt32(1)),
207+
},
208+
},
209+
},
210+
Status: clusterv1.MachineDeploymentStatus{V1Beta2: &clusterv1.MachineDeploymentV1Beta2Status{AvailableReplicas: ptr.To(int32(0))}},
211+
},
212+
getAndAdoptMachineSetsForDeploymentSucceeded: true,
213+
expectCondition: metav1.Condition{
214+
Type: clusterv1.MachineDeploymentAvailableV1Beta2Condition,
215+
Status: metav1.ConditionFalse,
216+
Reason: clusterv1.MachineDeploymentNotAvailableV1Beta2Reason,
217+
Message: "Deletion in progress",
218+
},
219+
},
194220
}
195221
for _, tt := range tests {
196222
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)