Skip to content

Commit

Permalink
fix: update patch to use DefaultBackoff
Browse files Browse the repository at this point in the history
using DefaultBackoff rather than DefaultRetry should result in fewer conflicts with other controllers
in addition, we also change removeFinalizer() to use our patch function.
  • Loading branch information
cam-garrison committed Sep 4, 2024
1 parent a6fe071 commit b89f879
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions controllers/routingctrl/delete_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/unstruct/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit b89f879

Please sign in to comment.