Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Remove retry usages across the code #918

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading