From 5f4c08680a8158df89b3d6e07bcdc1a133c860f2 Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Thu, 4 Aug 2022 10:13:07 +0800 Subject: [PATCH] retry to remove the pediacluster's finalizer Signed-off-by: Iceber Gu --- pkg/synchromanager/clustersynchro_manager.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/synchromanager/clustersynchro_manager.go b/pkg/synchromanager/clustersynchro_manager.go index 5df6d8b5f..b96c03fde 100644 --- a/pkg/synchromanager/clustersynchro_manager.go +++ b/pkg/synchromanager/clustersynchro_manager.go @@ -246,9 +246,18 @@ func (manager *Manager) reconcileCluster(cluster *clusterv1alpha2.PediaCluster) return controller.NoRequeueResult } - // remove finalizer - controllerutil.RemoveFinalizer(cluster, ClusterSynchroControllerFinalizer) - if _, err := manager.clusterpediaclient.ClusterV1alpha2().PediaClusters().Update(context.TODO(), cluster, metav1.UpdateOptions{}); err != nil { + if err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + cluster, err := manager.clusterlister.Get(cluster.Name) + if err != nil { + return err + } + cluster = cluster.DeepCopy() + + // remove finalizer + controllerutil.RemoveFinalizer(cluster, ClusterSynchroControllerFinalizer) + _, err = manager.clusterpediaclient.ClusterV1alpha2().PediaClusters().Update(context.TODO(), cluster, metav1.UpdateOptions{}) + return err + }); err != nil && !apierrors.IsNotFound(err) { klog.ErrorS(err, "Failed to remove finializer", "cluster", cluster.Name) return controller.RequeueResult(defaultRetryNum) }