From ca0547768fb8eac0a05acfaea3f6c845ed4942f8 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Tue, 10 Dec 2024 14:35:22 +0100 Subject: [PATCH] Remove retry usages across the code Signed-off-by: Danil-Grigorev --- internal/controllers/import_controller_v3.go | 10 ++----- internal/controllers/patch_kcfg_controller.go | 26 +++++++------------ internal/sync/core.go | 5 +--- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/internal/controllers/import_controller_v3.go b/internal/controllers/import_controller_v3.go index 984dd2f1..8d75303f 100644 --- a/internal/controllers/import_controller_v3.go +++ b/internal/controllers/import_controller_v3.go @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" errorutils "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/tools/record" - "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -184,13 +183,8 @@ func (r *CAPIImportManagementV3Reconciler) Reconcile(ctx context.Context, req ct errs = append(errs, fmt.Errorf("error reconciling cluster: %w", err)) } - if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error { - if err := r.Client.Patch(ctx, capiCluster, patchBase); err != nil { - errs = append(errs, fmt.Errorf("failed to patch cluster: %w", err)) - } - return nil - }); err != nil { - return ctrl.Result{}, err + if err := r.Client.Patch(ctx, capiCluster, patchBase); err != nil { + errs = append(errs, fmt.Errorf("failed to patch cluster: %w", err)) } if len(errs) > 0 { diff --git a/internal/controllers/patch_kcfg_controller.go b/internal/controllers/patch_kcfg_controller.go index 572e2dc5..97d887fd 100644 --- a/internal/controllers/patch_kcfg_controller.go +++ b/internal/controllers/patch_kcfg_controller.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" - "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -113,26 +112,21 @@ func (r *RancherKubeconfigSecretReconciler) Reconcile(ctx context.Context, req c return ctrl.Result{}, nil } - if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error { - secretCopy := secret.DeepCopy() - if secretCopy.Labels == nil { - secretCopy.Labels = map[string]string{} - } - secretCopy.Labels[clusterv1.ClusterNameLabel] = clusterName + secretCopy := secret.DeepCopy() + if secretCopy.Labels == nil { + secretCopy.Labels = map[string]string{} + } - patchBase := client.MergeFromWithOptions(secret, client.MergeFromWithOptimisticLock{}) + secretCopy.Labels[clusterv1.ClusterNameLabel] = clusterName - if err := r.Client.Patch(ctx, secretCopy, patchBase); err != nil { - return fmt.Errorf("failed to patch secret: %w", err) - } + patchBase := client.MergeFromWithOptions(secret, client.MergeFromWithOptimisticLock{}) - log.V(4).Info("patched kubeconfig secret", "name", secret.Name, "namespace", secret.Namespace, "cluster", clusterName) - - return nil - }); err != nil { - return ctrl.Result{}, err + if err := r.Client.Patch(ctx, secretCopy, patchBase); err != nil { + return ctrl.Result{}, fmt.Errorf("failed to patch secret: %w", err) } + log.V(4).Info("patched kubeconfig secret", "name", secret.Name, "namespace", secret.Namespace, "cluster", clusterName) + return ctrl.Result{}, nil } diff --git a/internal/sync/core.go b/internal/sync/core.go index a2e88c8d..3ed70a68 100644 --- a/internal/sync/core.go +++ b/internal/sync/core.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kerrors "k8s.io/apimachinery/pkg/util/errors" - "k8s.io/client-go/util/retry" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" @@ -66,9 +65,7 @@ func (s *DefaultSynchronizer) Apply(ctx context.Context, reterr *error) { setOwnerReference(s.Source, s.Destination) - if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error { - return Patch(ctx, s.client, s.Destination) - }); err != nil { + if err := Patch(ctx, s.client, s.Destination); err != nil { *reterr = kerrors.NewAggregate([]error{*reterr, err}) log.Error(*reterr, fmt.Sprintf("Unable to patch object: %s", *reterr)) }