From b004bcc6143e745bcb47d5c05e8ca30ccd7a6b9a Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 22 Aug 2022 22:06:14 +0800 Subject: [PATCH] Apply only when having finalizer (#270) Signed-off-by: Jian Qiu Signed-off-by: Jian Qiu --- .../klusterletcontroller/klusterlet_controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go b/pkg/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go index 6f926e485..0f8137236 100644 --- a/pkg/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go +++ b/pkg/operators/klusterlet/controllers/klusterletcontroller/klusterlet_controller.go @@ -311,6 +311,11 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto return nil } + // do nothing until finalizer is added. + if !hasFinalizer(klusterlet, klusterletFinalizer) { + return nil + } + if !readyToOperateManagedClusterResources(klusterlet, config.InstallMode) { // wait for the external managed kubeconfig to exist to apply resources on the manged cluster return nil @@ -466,7 +471,7 @@ func readyToOperateManagedClusterResources(klusterlet *operatorapiv1.Klusterlet, return true } - return meta.IsStatusConditionTrue(klusterlet.Status.Conditions, klusterletReadyToApply) + return meta.IsStatusConditionTrue(klusterlet.Status.Conditions, klusterletReadyToApply) && hasFinalizer(klusterlet, klusterletHostedFinalizer) } // getClusterNameFromHubKubeConfigSecret gets cluster name from hub kubeConfig secret