@@ -105,10 +105,17 @@ type Cluster struct {
105
105
}
106
106
107
107
type 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
112
119
}
113
120
114
121
// New creates a new cluster. This function should be called from a controller.
@@ -431,6 +438,7 @@ func (c *Cluster) Create() (err error) {
431
438
}
432
439
433
440
func (c * Cluster ) compareStatefulSetWith (statefulSet * appsv1.StatefulSet ) * compareStatefulsetResult {
441
+ deletedPodAnnotations := []string {}
434
442
reasons := make ([]string , 0 )
435
443
var match , needsRollUpdate , needsReplace bool
436
444
@@ -445,7 +453,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
445
453
needsReplace = true
446
454
reasons = append (reasons , "new statefulset's ownerReferences do not match" )
447
455
}
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 {
449
457
match = false
450
458
needsReplace = true
451
459
reasons = append (reasons , "new statefulset's annotations do not match: " + reason )
@@ -519,7 +527,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
519
527
}
520
528
}
521
529
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 {
523
531
match = false
524
532
needsReplace = true
525
533
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
541
549
reasons = append (reasons , fmt .Sprintf ("new statefulset's name for volume %d does not match the current one" , i ))
542
550
continue
543
551
}
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 {
545
553
needsReplace = true
546
554
reasons = append (reasons , fmt .Sprintf ("new statefulset's annotations for volume %q do not match the current ones: %s" , name , reason ))
547
555
}
@@ -579,7 +587,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
579
587
match = false
580
588
}
581
589
582
- return & compareStatefulsetResult {match : match , reasons : reasons , rollingUpdate : needsRollUpdate , replace : needsReplace }
590
+ return & compareStatefulsetResult {match : match , reasons : reasons , rollingUpdate : needsRollUpdate , replace : needsReplace , deletedPodAnnotations : deletedPodAnnotations }
583
591
}
584
592
585
593
type containerCondition func (a , b v1.Container ) bool
@@ -781,7 +789,7 @@ func volumeMountExists(mount v1.VolumeMount, mounts []v1.VolumeMount) bool {
781
789
return false
782
790
}
783
791
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 ) {
785
793
reason := ""
786
794
ignoredAnnotations := make (map [string ]bool )
787
795
for _ , ignore := range c .OpConfig .IgnoredAnnotations {
@@ -794,6 +802,9 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string)
794
802
}
795
803
if _ , ok := new [key ]; ! ok {
796
804
reason += fmt .Sprintf (" Removed %q." , key )
805
+ if removedList != nil {
806
+ * removedList = append (* removedList , key )
807
+ }
797
808
}
798
809
}
799
810
@@ -836,41 +847,46 @@ func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) {
836
847
return true , ""
837
848
}
838
849
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
840
854
841
855
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 ) )
844
858
}
845
859
846
860
newImage := new .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
847
861
curImage := cur .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
848
862
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 ) )
851
865
}
852
866
853
867
newPodAnnotation := new .Spec .JobTemplate .Spec .Template .Annotations
854
868
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 ))
857
872
}
858
873
859
874
newPgVersion := getPgVersion (new )
860
875
curPgVersion := getPgVersion (cur )
861
876
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 ) )
864
879
}
865
880
866
881
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 )
869
884
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 , `', '` )))
871
887
}
872
888
873
- return true , ""
889
+ return & compareLogicalBackupJobResult { match : match , reasons : reasons , deletedPodAnnotations : deletedPodAnnotations }
874
890
}
875
891
876
892
func (c * Cluster ) comparePodDisruptionBudget (cur , new * policyv1.PodDisruptionBudget ) (bool , string ) {
@@ -881,7 +897,7 @@ func (c *Cluster) comparePodDisruptionBudget(cur, new *policyv1.PodDisruptionBud
881
897
if ! reflect .DeepEqual (new .ObjectMeta .OwnerReferences , cur .ObjectMeta .OwnerReferences ) {
882
898
return false , "new PDB's owner references do not match the current ones"
883
899
}
884
- if changed , reason := c .compareAnnotations (cur .Annotations , new .Annotations ); changed {
900
+ if changed , reason := c .compareAnnotations (cur .Annotations , new .Annotations , nil ); changed {
885
901
return false , "new PDB's annotations do not match the current ones:" + reason
886
902
}
887
903
return true , ""
@@ -1021,7 +1037,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
1021
1037
// only when streams were not specified in oldSpec but in newSpec
1022
1038
needStreamUser := len (oldSpec .Spec .Streams ) == 0 && len (newSpec .Spec .Streams ) > 0
1023
1039
1024
- annotationsChanged , _ := c .compareAnnotations (oldSpec .Annotations , newSpec .Annotations )
1040
+ annotationsChanged , _ := c .compareAnnotations (oldSpec .Annotations , newSpec .Annotations , nil )
1025
1041
1026
1042
initUsers := ! sameUsers || ! sameRotatedUsers || needPoolerUser || needStreamUser
1027
1043
if initUsers {
0 commit comments