Skip to content

Commit b38e139

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Ensure moot labels are explicitly removed during upgrade
Presently, these keys are only removed if there is a value present in them, not if they are empty. This update ensures that they are removed regardless of contents.
1 parent 2063196 commit b38e139

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

internal/operator/cluster/upgrade.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -482,46 +482,46 @@ func preparePgclusterForUpgrade(pgcluster *crv1.Pgcluster, parameters map[string
482482
// that the value is migrated over
483483
if value, ok := pgcluster.ObjectMeta.Labels["crunchy_collect"]; ok {
484484
pgcluster.ObjectMeta.Labels[config.LABEL_EXPORTER] = value
485-
delete(pgcluster.ObjectMeta.Labels, "crunchy_collect")
486485
}
486+
delete(pgcluster.ObjectMeta.Labels, "crunchy_collect")
487487

488+
// Note that this is the *user labels*, the above is in the metadata labels
488489
if value, ok := pgcluster.Spec.UserLabels["crunchy_collect"]; ok {
489490
pgcluster.Spec.UserLabels[config.LABEL_EXPORTER] = value
490-
delete(pgcluster.Spec.UserLabels, "crunchy_collect")
491491
}
492+
delete(pgcluster.Spec.UserLabels, "crunchy_collect")
492493

493494
// convert the metrics label over to using a proper definition. Give the user
494495
// label precedence.
495496
if value, ok := pgcluster.ObjectMeta.Labels[config.LABEL_EXPORTER]; ok {
496497
pgcluster.Spec.Exporter, _ = strconv.ParseBool(value)
497-
delete(pgcluster.ObjectMeta.Labels, config.LABEL_EXPORTER)
498498
}
499+
delete(pgcluster.ObjectMeta.Labels, config.LABEL_EXPORTER)
499500

501+
// again, note this is *user* labels, the above are the metadata labels
500502
if value, ok := pgcluster.Spec.UserLabels[config.LABEL_EXPORTER]; ok {
501503
pgcluster.Spec.Exporter, _ = strconv.ParseBool(value)
502-
delete(pgcluster.Spec.UserLabels, config.LABEL_EXPORTER)
503504
}
505+
delete(pgcluster.Spec.UserLabels, config.LABEL_EXPORTER)
504506

505507
// 4.6.0 moved pgBadger to use an attribute instead of a label. If this label
506508
// exists on the current CRD, move the value to the attribute.
507509
if ok, _ := strconv.ParseBool(pgcluster.ObjectMeta.GetLabels()["crunchy-pgbadger"]); ok {
508510
pgcluster.Spec.PGBadger = true
509-
delete(pgcluster.ObjectMeta.Labels, "crunchy-pgbadger")
510511
}
512+
delete(pgcluster.ObjectMeta.Labels, "crunchy-pgbadger")
511513

512514
// 4.6.0 moved the format "service-type" label into the ServiceType CRD
513515
// attribute, so we may need to do the same
514516
if val, ok := pgcluster.Spec.UserLabels["service-type"]; ok {
515517
pgcluster.Spec.ServiceType = v1.ServiceType(val)
516-
delete(pgcluster.Spec.UserLabels, "service-type")
517518
}
519+
delete(pgcluster.Spec.UserLabels, "service-type")
518520

519521
// 4.6.0 moved the "autofail" label to the DisableAutofail attribute. Given
520522
// by default we need to start in an autofailover state, we just delete the
521523
// legacy attribute
522-
if _, ok := pgcluster.ObjectMeta.GetLabels()["autofail"]; ok {
523-
delete(pgcluster.ObjectMeta.Labels, "autofail")
524-
}
524+
delete(pgcluster.ObjectMeta.Labels, "autofail")
525525

526526
// 4.6.0 moved the node labels to the custom resource objects in a more
527527
// structure way. if we have a node label, then let's migrate it to that
@@ -548,11 +548,10 @@ func preparePgclusterForUpgrade(pgcluster *crv1.Pgcluster, parameters map[string
548548
PreferredDuringSchedulingIgnoredDuringExecution: []v1.PreferredSchedulingTerm{term},
549549
},
550550
}
551-
552-
// erase all trace of this
553-
delete(pgcluster.Spec.UserLabels, "NodeLabelKey")
554-
delete(pgcluster.Spec.UserLabels, "NodeLabelValue")
555551
}
552+
// erase all trace of this
553+
delete(pgcluster.Spec.UserLabels, "NodeLabelKey")
554+
delete(pgcluster.Spec.UserLabels, "NodeLabelValue")
556555

557556
// 4.6.0 moved the "backrest-storage-type" label to a CRD attribute, well,
558557
// really an array of CRD attributes, which we need to map the various
@@ -592,10 +591,9 @@ func preparePgclusterForUpgrade(pgcluster *crv1.Pgcluster, parameters map[string
592591
pgcluster.Spec.BackrestStorageTypes = append(pgcluster.Spec.BackrestStorageTypes,
593592
crv1.BackrestStorageTypePosix)
594593
}
595-
596-
// and delete the label
597-
delete(pgcluster.Spec.UserLabels, "backrest-storage-type")
598594
}
595+
// and delete the label
596+
delete(pgcluster.Spec.UserLabels, "backrest-storage-type")
599597

600598
// since the current primary label is not used in this version of the Postgres Operator,
601599
// delete it before moving on to other upgrade tasks

0 commit comments

Comments
 (0)