Skip to content

Commit

Permalink
Remove retry usages across the code
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Dec 10, 2024
1 parent ff062aa commit ca05477
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 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
5 changes: 1 addition & 4 deletions internal/sync/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit ca05477

Please sign in to comment.