From b89f879b7d7791d9c0252e9735e89e0aa873f4aa Mon Sep 17 00:00:00 2001 From: Cameron Garrison Date: Wed, 4 Sep 2024 09:27:29 -0400 Subject: [PATCH] fix: update patch to use DefaultBackoff using DefaultBackoff rather than DefaultRetry should result in fewer conflicts with other controllers in addition, we also change removeFinalizer() to use our patch function. --- controllers/routingctrl/delete_resources.go | 6 ++++-- pkg/unstruct/funcs.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/routingctrl/delete_resources.go b/controllers/routingctrl/delete_resources.go index c501686..c88c27b 100644 --- a/controllers/routingctrl/delete_resources.go +++ b/controllers/routingctrl/delete_resources.go @@ -6,6 +6,7 @@ import ( "github.com/opendatahub-io/odh-platform/pkg/metadata/labels" "github.com/opendatahub-io/odh-platform/pkg/routing" + "github.com/opendatahub-io/odh-platform/pkg/unstruct" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" k8slabels "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" @@ -90,8 +91,9 @@ func removeFinalizer(ctx context.Context, cli client.Client, sourceRes *unstruct if controllerutil.ContainsFinalizer(sourceRes, finalizerName) { controllerutil.RemoveFinalizer(sourceRes, finalizerName) - if err := cli.Update(ctx, sourceRes); err != nil { - return fmt.Errorf("failed to remove finalizer: %w", err) + if err := unstruct.Patch(ctx, cli, sourceRes); err != nil { + return fmt.Errorf("failed to remove finalizer patching resource %s/%s: %w", + sourceRes.GetNamespace(), sourceRes.GetName(), err) } } diff --git a/pkg/unstruct/funcs.go b/pkg/unstruct/funcs.go index c587a26..51af92e 100644 --- a/pkg/unstruct/funcs.go +++ b/pkg/unstruct/funcs.go @@ -66,7 +66,7 @@ func IsMarkedForDeletion(target *unstructured.Unstructured) bool { // Patch updates the specified Kubernetes resource by applying changes from the provided target object. // In case of conflicts, it will retry using default strategy. func Patch(ctx context.Context, cli client.Client, target *unstructured.Unstructured) error { - err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + err := retry.RetryOnConflict(retry.DefaultBackoff, func() error { currentRes := &unstructured.Unstructured{} currentRes.SetGroupVersionKind(target.GroupVersionKind())