From 3012c808f8cf9b1ea894ee008ba5520518a7bc49 Mon Sep 17 00:00:00 2001 From: chaosi-zju Date: Mon, 18 Mar 2024 11:23:17 +0800 Subject: [PATCH] fix deployment replicas syncer in case deployment status changed before label added Signed-off-by: chaosi-zju --- .../deployment_replicas_syncer_controller.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/controllers/deploymentreplicassyncer/deployment_replicas_syncer_controller.go b/pkg/controllers/deploymentreplicassyncer/deployment_replicas_syncer_controller.go index 18ef6849a221..04f09d8040da 100644 --- a/pkg/controllers/deploymentreplicassyncer/deployment_replicas_syncer_controller.go +++ b/pkg/controllers/deploymentreplicassyncer/deployment_replicas_syncer_controller.go @@ -57,6 +57,13 @@ var predicateFunc = predicate.Funcs{ return false } + // if old deployment is not labeled `retain-replicas`, but new is labeled, reconcile is needed. + // in case of deployment status changed before `retain-replicas` labeled. + oldRetainReplicasLabel := util.GetLabelValue(oldObj.GetLabels(), util.RetainReplicasLabel) + if oldRetainReplicasLabel != util.RetainReplicasValue { + return true + } + if oldObj.Spec.Replicas == nil || newObj.Spec.Replicas == nil { klog.Errorf("spec.replicas field unexpectedly become nil: %+v, %+v", oldObj.Spec.Replicas, newObj.Spec.Replicas) return false