Skip to content

Commit 5a4393b

Browse files
authored
Update annotation update behavior
The existing annotation update logic is unable to maintain existing 'global' annotations when a 'specific' (postgres, pgbackrest or pgbouncer) deployment annotation is updated (e.g. the Postgres only annotation is updated, but replaces any existing 'global' annotations that were made previously) and vice versa. To remedy this, if either 'global' or 'specific' deployment annotations are updated, the relevant map is updated to include all existing 'global' or 'specific' annotations from the pgcluster CRD. 'Global' annotations with the same key value of a 'specific' annotation will be overwritten, so that the more specific annotation is authoritative.
1 parent 93a00e4 commit 5a4393b

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

internal/controller/pgcluster/pgclustercontroller.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,31 +346,42 @@ func updateAnnotations(c *Controller, oldCluster *crv1.Pgcluster, newCluster *cr
346346
annotationsBackrest := map[string]string{}
347347
annotationsPgBouncer := map[string]string{}
348348

349-
// if the global ones differ, make the changes for all of the annotations
350-
if !reflect.DeepEqual(oldCluster.Spec.Annotations.Global, newCluster.Spec.Annotations.Global) {
351-
// set the annotations for all of them
349+
// check the individual deployment groups. If the annotations differ in either the specific group or
350+
// in the global group, set them in their respective map
351+
if !reflect.DeepEqual(oldCluster.Spec.Annotations.Postgres, newCluster.Spec.Annotations.Postgres) ||
352+
!reflect.DeepEqual(oldCluster.Spec.Annotations.Global, newCluster.Spec.Annotations.Global) {
353+
// store the global annotations first
352354
for k, v := range newCluster.Spec.Annotations.Global {
353355
annotationsPostgres[k] = v
354-
annotationsBackrest[k] = v
355-
annotationsPgBouncer[k] = v
356356
}
357-
}
358357

359-
// check the individual deployment groups. If the annotations differ, set them
360-
// in their respective map
361-
if !reflect.DeepEqual(oldCluster.Spec.Annotations.Postgres, newCluster.Spec.Annotations.Postgres) {
358+
// then store the postgres specific annotations
362359
for k, v := range newCluster.Spec.Annotations.Postgres {
363360
annotationsPostgres[k] = v
364361
}
365362
}
366363

367-
if !reflect.DeepEqual(oldCluster.Spec.Annotations.Backrest, newCluster.Spec.Annotations.Backrest) {
364+
if !reflect.DeepEqual(oldCluster.Spec.Annotations.Backrest, newCluster.Spec.Annotations.Backrest) ||
365+
!reflect.DeepEqual(oldCluster.Spec.Annotations.Global, newCluster.Spec.Annotations.Global) {
366+
// store the global annotations first
367+
for k, v := range newCluster.Spec.Annotations.Global {
368+
annotationsBackrest[k] = v
369+
}
370+
371+
// then store the pgbackrest specific annotations
368372
for k, v := range newCluster.Spec.Annotations.Backrest {
369373
annotationsBackrest[k] = v
370374
}
371375
}
372376

373-
if !reflect.DeepEqual(oldCluster.Spec.Annotations.PgBouncer, newCluster.Spec.Annotations.PgBouncer) {
377+
if !reflect.DeepEqual(oldCluster.Spec.Annotations.PgBouncer, newCluster.Spec.Annotations.PgBouncer) ||
378+
!reflect.DeepEqual(oldCluster.Spec.Annotations.Global, newCluster.Spec.Annotations.Global) {
379+
// store the global annotations first
380+
for k, v := range newCluster.Spec.Annotations.Global {
381+
annotationsPgBouncer[k] = v
382+
}
383+
384+
// then store the pgbouncer specific annotations
374385
for k, v := range newCluster.Spec.Annotations.PgBouncer {
375386
annotationsPgBouncer[k] = v
376387
}

0 commit comments

Comments
 (0)