Skip to content

Commit e5799cb

Browse files
committed
workloadscontroller: ensure all code paths explicitly set conditions and their statuses
1 parent c111ff1 commit e5799cb

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

pkg/operator/apiserver/controller/workload/workload.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,16 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
165165
}
166166

167167
deploymentAvailableCondition := applyoperatorv1.OperatorCondition().
168-
WithType(fmt.Sprintf("%sDeployment%s", c.conditionsPrefix, operatorv1.OperatorStatusTypeAvailable)).
169-
WithStatus(operatorv1.ConditionTrue)
168+
WithType(fmt.Sprintf("%sDeployment%s", c.conditionsPrefix, operatorv1.OperatorStatusTypeAvailable))
170169

171170
workloadDegradedCondition := applyoperatorv1.OperatorCondition().
172-
WithType(fmt.Sprintf("%sWorkloadDegraded", c.conditionsPrefix)).
173-
WithStatus(operatorv1.ConditionFalse)
171+
WithType(fmt.Sprintf("%sWorkloadDegraded", c.conditionsPrefix))
174172

175173
deploymentDegradedCondition := applyoperatorv1.OperatorCondition().
176-
WithType(fmt.Sprintf("%sDeploymentDegraded", c.conditionsPrefix)).
177-
WithStatus(operatorv1.ConditionFalse)
174+
WithType(fmt.Sprintf("%sDeploymentDegraded", c.conditionsPrefix))
178175

179176
deploymentProgressingCondition := applyoperatorv1.OperatorCondition().
180-
WithType(fmt.Sprintf("%sDeployment%s", c.conditionsPrefix, operatorv1.OperatorStatusTypeProgressing)).
181-
WithStatus(operatorv1.ConditionFalse)
177+
WithType(fmt.Sprintf("%sDeployment%s", c.conditionsPrefix, operatorv1.OperatorStatusTypeProgressing))
182178

183179
status := applyoperatorv1.OperatorStatus()
184180
defer func() {
@@ -218,6 +214,11 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
218214
WithStatus(operatorv1.ConditionFalse).
219215
WithReason("PreconditionNotFulfilled")
220216

217+
workloadDegradedCondition = workloadDegradedCondition.
218+
WithStatus(operatorv1.ConditionTrue).
219+
WithReason("PreconditionNotFulfilled").
220+
WithMessage(message)
221+
221222
return kerrors.NewAggregate(errs)
222223
}
223224

@@ -252,6 +253,11 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o
252253
WithReason("NoDeployment").
253254
WithMessage(message)
254255

256+
workloadDegradedCondition = workloadDegradedCondition.
257+
WithStatus(operatorv1.ConditionTrue).
258+
WithReason("NoDeployment").
259+
WithMessage(message)
260+
255261
return kerrors.NewAggregate(errs)
256262
}
257263

pkg/operator/apiserver/controller/workload/workload_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ func TestUpdateOperatorStatus(t *testing.T) {
7171
Message: "deployment/: could not be retrieved",
7272
},
7373
{
74-
Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName),
75-
Status: operatorv1.ConditionFalse,
74+
Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName),
75+
Status: operatorv1.ConditionTrue,
76+
Reason: "NoDeployment",
77+
Message: "deployment/: could not be retrieved",
7678
},
7779
{
7880
Type: fmt.Sprintf("%sDeploymentDegraded", defaultControllerName),
@@ -105,8 +107,8 @@ func TestUpdateOperatorStatus(t *testing.T) {
105107
{
106108
Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName),
107109
Status: operatorv1.ConditionTrue,
108-
Message: "nasty error\n",
109-
Reason: "SyncError",
110+
Reason: "NoDeployment",
111+
Message: "deployment/: could not be retrieved",
110112
},
111113
{
112114
Type: fmt.Sprintf("%sDeploymentDegraded", defaultControllerName),
@@ -441,8 +443,10 @@ func TestUpdateOperatorStatus(t *testing.T) {
441443
Message: "",
442444
},
443445
{
444-
Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName),
445-
Status: operatorv1.ConditionFalse,
446+
Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName),
447+
Status: operatorv1.ConditionTrue,
448+
Reason: "PreconditionNotFulfilled",
449+
Message: "the operator didn't specify what preconditions are missing",
446450
},
447451
}
448452
return areCondidtionsEqual(expectedConditions, actualStatus.Conditions)

0 commit comments

Comments
 (0)