Skip to content

Commit

Permalink
fix: delete cluster failed when failed to remove finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-lucky committed Jun 13, 2024
1 parent 7326e14 commit 48ebf0c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/controllers/federatedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"

fedcorev1a1 "github.com/kubewharf/kubeadmiral/pkg/apis/core/v1alpha1"
Expand Down Expand Up @@ -457,12 +458,19 @@ func (c *FederatedClusterController) handleTerminatingCluster(
}

// We have already checked that we are the last finalizer so we can simply set finalizers to be empty.
cluster.SetFinalizers(nil)
if _, err := c.fedClient.CoreV1alpha1().FederatedClusters().Update(
ctx,
cluster,
metav1.UpdateOptions{},
); err != nil {
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
var err error
cluster.SetFinalizers(nil)

_, updateErr := c.fedClient.CoreV1alpha1().FederatedClusters().Update(ctx, cluster, metav1.UpdateOptions{})
if updateErr != nil && apierrors.IsConflict(updateErr) {
cluster, err = c.fedClient.CoreV1alpha1().FederatedClusters().Get(ctx, cluster.Name, metav1.GetOptions{ResourceVersion: "0"})
if err != nil {
return err
}
}
return updateErr
}); err != nil {
return fmt.Errorf("failed to update cluster for finalizer removal: %w", err)
}

Expand Down

0 comments on commit 48ebf0c

Please sign in to comment.