Skip to content

Commit da68cf6

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

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

percona/controller/pgcluster/controller.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,21 @@ 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()
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()
342345

343-
cr.Status.PatroniVersion = patroniVersion
346+
cr.Status.PatroniVersion = patroniVersion
344347

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")
348+
if err := r.Client.Status().Patch(ctx, cr.DeepCopy(), client.MergeFrom(orig)); err != nil {
349+
return errors.Wrap(err, "failed to patch patroni version")
350+
}
351+
return nil
352+
})
353+
if err != nil {
354+
return errors.Wrap(err, "failed to execute retry on patroni version")
347355
}
348-
349356
return nil
350357
}
351358

0 commit comments

Comments
 (0)