Skip to content

Commit 1fc1770

Browse files
committed
cr: add retry on conflict to ensure update when changes happen at the same time
1 parent c5c9654 commit 1fc1770

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

percona/controller/pgcluster/controller.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,20 @@ func (r *PGClusterReconciler) reconcilePatroniVersionCheck(ctx context.Context,
338338
if patroniVersion, ok := cr.Annotations[pNaming.AnnotationCustomPatroniVersion]; ok {
339339
cr.Annotations[pNaming.AnnotationPatroniVersion] = patroniVersion
340340

341-
orig := cr.DeepCopy()
342-
343-
cr.Status.PatroniVersion = patroniVersion
344-
345-
if err := r.Client.Status().Patch(ctx, cr.DeepCopy(), client.MergeFrom(orig)); err != nil {
346-
return errors.Wrap(err, "failed to patch patroni version")
341+
// To ensure that the update was done given that conflicts can be caused by
342+
// other code making unrelated updates to the same resource at the same time.
343+
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
344+
orig := cr.DeepCopy()
345+
346+
cr.Status.PatroniVersion = patroniVersion
347+
if err := r.Client.Status().Patch(ctx, cr.DeepCopy(), client.MergeFrom(orig)); err != nil {
348+
return errors.Wrap(err, "failed to patch patroni version")
349+
}
350+
return nil
351+
})
352+
if err != nil {
353+
return errors.Wrap(err, "failed to execute retry on patroni version")
347354
}
348-
349355
return nil
350356
}
351357

0 commit comments

Comments
 (0)