@@ -31,9 +31,15 @@ var errPatroniVersionCheckWait = errors.New("waiting for pod to initialize")
3131
3232func (r * PGClusterReconciler ) reconcilePatroniVersion (ctx context.Context , cr * v2.PerconaPGCluster ) error {
3333 if cr .CompareVersion ("2.7.0" ) <= 0 {
34- err := r .handleCustomPatroniVersionAnnotation (ctx , cr )
35- if err != nil {
36- return errors .Wrap (err , "handle patroni annotation" )
34+ if cr .Annotations == nil {
35+ cr .Annotations = make (map [string ]string )
36+ }
37+ if patroniVersion , ok := cr .Annotations [pNaming .AnnotationCustomPatroniVersion ]; ok {
38+ err := r .handleCustomPatroniVersionAnnotation (ctx , cr , patroniVersion )
39+ if err != nil {
40+ return errors .Wrap (err , "handle patroni annotation" )
41+ }
42+ return nil
3743 }
3844 }
3945
@@ -228,45 +234,38 @@ func (r *PGClusterReconciler) getPatroniVersion(ctx context.Context, pod *corev1
228234 return patroniVersion , nil
229235}
230236
231- func (r * PGClusterReconciler ) handleCustomPatroniVersionAnnotation (ctx context.Context , cr * v2.PerconaPGCluster ) error {
232- if cr .Annotations == nil {
233- cr .Annotations = make (map [string ]string )
234- }
235-
236- if patroniVersion , ok := cr .Annotations [pNaming .AnnotationCustomPatroniVersion ]; ok {
237- patroniVersionUpdateFunc := func () error {
238- cluster := & v2.PerconaPGCluster {}
239- if err := r .Client .Get (ctx , types.NamespacedName {
240- Name : cr .Name ,
241- Namespace : cr .Namespace ,
242- }, cluster ); err != nil {
243- return errors .Wrap (err , "get PerconaPGCluster" )
244- }
245-
246- orig := cluster .DeepCopy ()
247-
248- cluster .Status .Patroni .Version = patroniVersion
249- cluster .Status .PatroniVersion = patroniVersion
237+ func (r * PGClusterReconciler ) handleCustomPatroniVersionAnnotation (ctx context.Context , cr * v2.PerconaPGCluster , patroniVersion string ) error {
238+ patroniVersionUpdateFunc := func () error {
239+ cluster := & v2.PerconaPGCluster {}
240+ if err := r .Client .Get (ctx , types.NamespacedName {
241+ Name : cr .Name ,
242+ Namespace : cr .Namespace ,
243+ }, cluster ); err != nil {
244+ return errors .Wrap (err , "get PerconaPGCluster" )
245+ }
250246
251- if err := r .Client .Status ().Patch (ctx , cluster .DeepCopy (), client .MergeFrom (orig )); err != nil {
252- return errors .Wrap (err , "failed to patch patroni version" )
253- }
247+ orig := cluster .DeepCopy ()
254248
255- err := r .patchPatroniVersionAnnotation (ctx , cr , patroniVersion )
256- if err != nil {
257- return errors .Wrap (err , "failed to patch patroni version annotation" )
258- }
249+ cluster .Status .Patroni .Version = patroniVersion
250+ cluster .Status .PatroniVersion = patroniVersion
259251
260- return nil
252+ if err := r .Client .Status ().Patch (ctx , cluster .DeepCopy (), client .MergeFrom (orig )); err != nil {
253+ return errors .Wrap (err , "failed to patch patroni version" )
261254 }
262255
263- // To ensure that the update was done given that conflicts can be caused by
264- // other code making unrelated updates to the same resource at the same time.
265- if err := retry .RetryOnConflict (retry .DefaultRetry , patroniVersionUpdateFunc ); err != nil {
266- return errors .Wrap (err , "failed to patch patroni version" )
256+ err := r .patchPatroniVersionAnnotation (ctx , cr , patroniVersion )
257+ if err != nil {
258+ return errors .Wrap (err , "failed to patch patroni version annotation" )
267259 }
260+
268261 return nil
269262 }
263+
264+ // To ensure that the update was done given that conflicts can be caused by
265+ // other code making unrelated updates to the same resource at the same time.
266+ if err := retry .RetryOnConflict (retry .DefaultRetry , patroniVersionUpdateFunc ); err != nil {
267+ return errors .Wrap (err , "failed to patch patroni version" )
268+ }
270269 return nil
271270}
272271
0 commit comments