From ed9ab117609c9b0c195cc9c41920f2abafc6648b Mon Sep 17 00:00:00 2001 From: Fabio Bertinatto Date: Mon, 14 Oct 2024 15:31:36 -0300 Subject: [PATCH] workloadscontroller: don't overwrite degraded condition if it's already set --- pkg/operator/apiserver/controller/workload/workload.go | 10 +++++----- .../apiserver/controller/workload/workload_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/operator/apiserver/controller/workload/workload.go b/pkg/operator/apiserver/controller/workload/workload.go index b466302dfa..5607995030 100644 --- a/pkg/operator/apiserver/controller/workload/workload.go +++ b/pkg/operator/apiserver/controller/workload/workload.go @@ -241,6 +241,11 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o WithStatus(operatorv1.ConditionTrue). WithReason("SyncError"). WithMessage(message) + } else if workload == nil { + workloadDegradedCondition = workloadDegradedCondition. + WithStatus(operatorv1.ConditionTrue). + WithReason("NoDeployment"). + WithMessage(fmt.Sprintf("deployment/%s: could not be retrieved", c.targetNamespace)) } else { workloadDegradedCondition = workloadDegradedCondition. WithStatus(operatorv1.ConditionFalse) @@ -263,11 +268,6 @@ func (c *Controller) updateOperatorStatus(ctx context.Context, previousStatus *o WithReason("NoDeployment"). WithMessage(message) - workloadDegradedCondition = workloadDegradedCondition. - WithStatus(operatorv1.ConditionTrue). - WithReason("NoDeployment"). - WithMessage(message) - return kerrors.NewAggregate(errs) } diff --git a/pkg/operator/apiserver/controller/workload/workload_test.go b/pkg/operator/apiserver/controller/workload/workload_test.go index 1723c57970..a518940743 100644 --- a/pkg/operator/apiserver/controller/workload/workload_test.go +++ b/pkg/operator/apiserver/controller/workload/workload_test.go @@ -107,8 +107,8 @@ func TestUpdateOperatorStatus(t *testing.T) { { Type: fmt.Sprintf("%sWorkloadDegraded", defaultControllerName), Status: operatorv1.ConditionTrue, - Reason: "NoDeployment", - Message: "deployment/: could not be retrieved", + Message: "nasty error\n", + Reason: "SyncError", }, { Type: fmt.Sprintf("%sDeploymentDegraded", defaultControllerName),