@@ -105,10 +105,17 @@ type Cluster struct {
105105}
106106
107107type compareStatefulsetResult struct {
108- match bool
109- replace bool
110- rollingUpdate bool
111- reasons []string
108+ match bool
109+ replace bool
110+ rollingUpdate bool
111+ reasons []string
112+ deletedPodAnnotations []string
113+ }
114+
115+ type compareLogicalBackupJobResult struct {
116+ match bool
117+ reasons []string
118+ deletedPodAnnotations []string
112119}
113120
114121// New creates a new cluster. This function should be called from a controller.
@@ -431,6 +438,7 @@ func (c *Cluster) Create() (err error) {
431438}
432439
433440func (c * Cluster ) compareStatefulSetWith (statefulSet * appsv1.StatefulSet ) * compareStatefulsetResult {
441+ deletedPodAnnotations := []string {}
434442 reasons := make ([]string , 0 )
435443 var match , needsRollUpdate , needsReplace bool
436444
@@ -445,7 +453,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
445453 needsReplace = true
446454 reasons = append (reasons , "new statefulset's ownerReferences do not match" )
447455 }
448- if changed , reason := c .compareAnnotations (c .Statefulset .Annotations , statefulSet .Annotations ); changed {
456+ if changed , reason := c .compareAnnotations (c .Statefulset .Annotations , statefulSet .Annotations , nil ); changed {
449457 match = false
450458 needsReplace = true
451459 reasons = append (reasons , "new statefulset's annotations do not match: " + reason )
@@ -519,7 +527,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
519527 }
520528 }
521529
522- if changed , reason := c .compareAnnotations (c .Statefulset .Spec .Template .Annotations , statefulSet .Spec .Template .Annotations ); changed {
530+ if changed , reason := c .compareAnnotations (c .Statefulset .Spec .Template .Annotations , statefulSet .Spec .Template .Annotations , & deletedPodAnnotations ); changed {
523531 match = false
524532 needsReplace = true
525533 reasons = append (reasons , "new statefulset's pod template metadata annotations does not match " + reason )
@@ -541,7 +549,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
541549 reasons = append (reasons , fmt .Sprintf ("new statefulset's name for volume %d does not match the current one" , i ))
542550 continue
543551 }
544- if changed , reason := c .compareAnnotations (c .Statefulset .Spec .VolumeClaimTemplates [i ].Annotations , statefulSet .Spec .VolumeClaimTemplates [i ].Annotations ); changed {
552+ if changed , reason := c .compareAnnotations (c .Statefulset .Spec .VolumeClaimTemplates [i ].Annotations , statefulSet .Spec .VolumeClaimTemplates [i ].Annotations , nil ); changed {
545553 needsReplace = true
546554 reasons = append (reasons , fmt .Sprintf ("new statefulset's annotations for volume %q do not match the current ones: %s" , name , reason ))
547555 }
@@ -579,7 +587,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
579587 match = false
580588 }
581589
582- return & compareStatefulsetResult {match : match , reasons : reasons , rollingUpdate : needsRollUpdate , replace : needsReplace }
590+ return & compareStatefulsetResult {match : match , reasons : reasons , rollingUpdate : needsRollUpdate , replace : needsReplace , deletedPodAnnotations : deletedPodAnnotations }
583591}
584592
585593type containerCondition func (a , b v1.Container ) bool
@@ -781,7 +789,7 @@ func volumeMountExists(mount v1.VolumeMount, mounts []v1.VolumeMount) bool {
781789 return false
782790}
783791
784- func (c * Cluster ) compareAnnotations (old , new map [string ]string ) (bool , string ) {
792+ func (c * Cluster ) compareAnnotations (old , new map [string ]string , removedList * [] string ) (bool , string ) {
785793 reason := ""
786794 ignoredAnnotations := make (map [string ]bool )
787795 for _ , ignore := range c .OpConfig .IgnoredAnnotations {
@@ -794,6 +802,9 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string)
794802 }
795803 if _ , ok := new [key ]; ! ok {
796804 reason += fmt .Sprintf (" Removed %q." , key )
805+ if removedList != nil {
806+ * removedList = append (* removedList , key )
807+ }
797808 }
798809 }
799810
@@ -836,41 +847,46 @@ func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) {
836847 return true , ""
837848}
838849
839- func (c * Cluster ) compareLogicalBackupJob (cur , new * batchv1.CronJob ) (match bool , reason string ) {
850+ func (c * Cluster ) compareLogicalBackupJob (cur , new * batchv1.CronJob ) * compareLogicalBackupJobResult {
851+ deletedPodAnnotations := []string {}
852+ reasons := make ([]string , 0 )
853+ match := true
840854
841855 if cur .Spec .Schedule != new .Spec .Schedule {
842- return false , fmt . Sprintf ( "new job's schedule %q does not match the current one %q" ,
843- new .Spec .Schedule , cur .Spec .Schedule )
856+ match = false
857+ reasons = append ( reasons , fmt . Sprintf ( " new job's schedule %q does not match the current one %q" , new .Spec .Schedule , cur .Spec .Schedule ) )
844858 }
845859
846860 newImage := new .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
847861 curImage := cur .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
848862 if newImage != curImage {
849- return false , fmt . Sprintf ( "new job's image %q does not match the current one %q" ,
850- newImage , curImage )
863+ match = false
864+ reasons = append ( reasons , fmt . Sprintf ( "new job's image %q does not match the current one %q" , newImage , curImage ) )
851865 }
852866
853867 newPodAnnotation := new .Spec .JobTemplate .Spec .Template .Annotations
854868 curPodAnnotation := cur .Spec .JobTemplate .Spec .Template .Annotations
855- if changed , reason := c .compareAnnotations (curPodAnnotation , newPodAnnotation ); changed {
856- return false , fmt .Sprintf ("new job's pod template metadata annotations does not match " + reason )
869+ if changed , reason := c .compareAnnotations (curPodAnnotation , newPodAnnotation , & deletedPodAnnotations ); changed {
870+ match = false
871+ reasons = append (reasons , fmt .Sprint ("new job's pod template metadata annotations do not match " + reason ))
857872 }
858873
859874 newPgVersion := getPgVersion (new )
860875 curPgVersion := getPgVersion (cur )
861876 if newPgVersion != curPgVersion {
862- return false , fmt . Sprintf ( "new job's env PG_VERSION %q does not match the current one %q" ,
863- newPgVersion , curPgVersion )
877+ match = false
878+ reasons = append ( reasons , fmt . Sprintf ( "new job's env PG_VERSION %q does not match the current one %q" , newPgVersion , curPgVersion ) )
864879 }
865880
866881 needsReplace := false
867- reasons := make ([]string , 0 )
868- needsReplace , reasons = c .compareContainers ("cronjob container" , cur .Spec .JobTemplate .Spec .Template .Spec .Containers , new .Spec .JobTemplate .Spec .Template .Spec .Containers , needsReplace , reasons )
882+ contReasons := make ([]string , 0 )
883+ needsReplace , contReasons = c .compareContainers ("cronjob container" , cur .Spec .JobTemplate .Spec .Template .Spec .Containers , new .Spec .JobTemplate .Spec .Template .Spec .Containers , needsReplace , contReasons )
869884 if needsReplace {
870- return false , fmt .Sprintf ("logical backup container specs do not match: %v" , strings .Join (reasons , `', '` ))
885+ match = false
886+ reasons = append (reasons , fmt .Sprintf ("logical backup container specs do not match: %v" , strings .Join (contReasons , `', '` )))
871887 }
872888
873- return true , ""
889+ return & compareLogicalBackupJobResult { match : match , reasons : reasons , deletedPodAnnotations : deletedPodAnnotations }
874890}
875891
876892func (c * Cluster ) comparePodDisruptionBudget (cur , new * policyv1.PodDisruptionBudget ) (bool , string ) {
@@ -881,7 +897,7 @@ func (c *Cluster) comparePodDisruptionBudget(cur, new *policyv1.PodDisruptionBud
881897 if ! reflect .DeepEqual (new .ObjectMeta .OwnerReferences , cur .ObjectMeta .OwnerReferences ) {
882898 return false , "new PDB's owner references do not match the current ones"
883899 }
884- if changed , reason := c .compareAnnotations (cur .Annotations , new .Annotations ); changed {
900+ if changed , reason := c .compareAnnotations (cur .Annotations , new .Annotations , nil ); changed {
885901 return false , "new PDB's annotations do not match the current ones:" + reason
886902 }
887903 return true , ""
@@ -1021,7 +1037,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
10211037 // only when streams were not specified in oldSpec but in newSpec
10221038 needStreamUser := len (oldSpec .Spec .Streams ) == 0 && len (newSpec .Spec .Streams ) > 0
10231039
1024- annotationsChanged , _ := c .compareAnnotations (oldSpec .Annotations , newSpec .Annotations )
1040+ annotationsChanged , _ := c .compareAnnotations (oldSpec .Annotations , newSpec .Annotations , nil )
10251041
10261042 initUsers := ! sameUsers || ! sameRotatedUsers || needPoolerUser || needStreamUser
10271043 if initUsers {
0 commit comments