Skip to content

Commit

Permalink
Remove retry usages across the code (#918)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev authored Dec 12, 2024
1 parent a45c388 commit 14c5831
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
10 changes: 2 additions & 8 deletions internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 10 additions & 16 deletions internal/controllers/patch_kcfg_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 14c5831

Please sign in to comment.