Skip to content

Commit

Permalink
Rely on retry.RetryOnConflict()
Browse files Browse the repository at this point in the history
Thanks Feilian, no sense reinventing the wheel!
  • Loading branch information
bentito committed Jul 13, 2023
1 parent 28a35d3 commit 4f25b93
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/operator/credentialsrequest/credentialsrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/util/retry"
"reflect"
"time"

Expand Down Expand Up @@ -1064,19 +1065,11 @@ func (r *ReconcileCredentialsRequest) UpdateProvisionedStatus(cr *minterv1.Crede
cr.Status.Provisioned = provisioned
}

// Use UpdateProvisionedStatus method to update only the status subresource
err := r.Client.Status().Update(context.Background(), cr)
// Use retry.RetryOnConflict() to update the status subresource
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
return r.Client.Status().Update(context.Background(), cr)
})
if err != nil {
// Handle possible errors from the API server
if errors.IsConflict(err) {
// Conflict error means that the object has been modified by another process
// Get the latest version of the object and retry the update operation
err := r.Client.Get(context.Background(), types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, cr)
if err != nil {
return err
}
return r.UpdateProvisionedStatus(cr, provisioned)
}
return err
}
return nil
Expand Down

0 comments on commit 4f25b93

Please sign in to comment.