@@ -378,9 +378,10 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
378
378
match = false
379
379
reasons = append (reasons , "new statefulset's number of replicas does not match the current one" )
380
380
}
381
- if ! reflect .DeepEqual (c .Statefulset .Annotations , statefulSet .Annotations ) {
381
+ if changed , reason := c .compareAnnotations (c .Statefulset .Annotations , statefulSet .Annotations ); changed {
382
+ match = false
382
383
needsReplace = true
383
- reasons = append (reasons , "new statefulset's annotations do not match the current one" )
384
+ reasons = append (reasons , "new statefulset's annotations do not match: " + reason )
384
385
}
385
386
386
387
needsRollUpdate , reasons = c .compareContainers ("initContainers" , c .Statefulset .Spec .Template .Spec .InitContainers , statefulSet .Spec .Template .Spec .InitContainers , needsRollUpdate , reasons )
@@ -434,10 +435,11 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
434
435
}
435
436
}
436
437
437
- if ! reflect .DeepEqual (c .Statefulset .Spec .Template .Annotations , statefulSet .Spec .Template .Annotations ) {
438
+ if changed , reason := c .compareAnnotations (c .Statefulset .Spec .Template .Annotations , statefulSet .Spec .Template .Annotations ); changed {
439
+ match = false
438
440
needsReplace = true
439
441
needsRollUpdate = true
440
- reasons = append (reasons , "new statefulset's pod template metadata annotations does not match the current one" )
442
+ reasons = append (reasons , "new statefulset's pod template metadata annotations does not match " + reason )
441
443
}
442
444
if ! reflect .DeepEqual (c .Statefulset .Spec .Template .Spec .SecurityContext , statefulSet .Spec .Template .Spec .SecurityContext ) {
443
445
needsReplace = true
@@ -672,6 +674,61 @@ func comparePorts(a, b []v1.ContainerPort) bool {
672
674
return true
673
675
}
674
676
677
+ func (c * Cluster ) compareAnnotations (old , new map [string ]string ) (bool , string ) {
678
+ reason := ""
679
+ ignoredAnnotations := make (map [string ]bool )
680
+ for _ , ignore := range c .OpConfig .IgnoredAnnotations {
681
+ ignoredAnnotations [ignore ] = true
682
+ }
683
+
684
+ for key := range old {
685
+ if _ , ok := ignoredAnnotations [key ]; ok {
686
+ continue
687
+ }
688
+ if _ , ok := new [key ]; ! ok {
689
+ reason += fmt .Sprintf (" Removed %q." , key )
690
+ }
691
+ }
692
+
693
+ for key := range new {
694
+ if _ , ok := ignoredAnnotations [key ]; ok {
695
+ continue
696
+ }
697
+ v , ok := old [key ]
698
+ if ! ok {
699
+ reason += fmt .Sprintf (" Added %q with value %q." , key , new [key ])
700
+ } else if v != new [key ] {
701
+ reason += fmt .Sprintf (" %q changed from %q to %q." , key , v , new [key ])
702
+ }
703
+ }
704
+
705
+ return reason != "" , reason
706
+
707
+ }
708
+
709
+ func (c * Cluster ) compareServices (old , new * v1.Service ) (bool , string ) {
710
+ if old .Spec .Type != new .Spec .Type {
711
+ return false , fmt .Sprintf ("new service's type %q does not match the current one %q" ,
712
+ new .Spec .Type , old .Spec .Type )
713
+ }
714
+
715
+ oldSourceRanges := old .Spec .LoadBalancerSourceRanges
716
+ newSourceRanges := new .Spec .LoadBalancerSourceRanges
717
+
718
+ /* work around Kubernetes 1.6 serializing [] as nil. See https://github.com/kubernetes/kubernetes/issues/43203 */
719
+ if (len (oldSourceRanges ) != 0 ) || (len (newSourceRanges ) != 0 ) {
720
+ if ! util .IsEqualIgnoreOrder (oldSourceRanges , newSourceRanges ) {
721
+ return false , "new service's LoadBalancerSourceRange does not match the current one"
722
+ }
723
+ }
724
+
725
+ if changed , reason := c .compareAnnotations (old .Annotations , new .Annotations ); changed {
726
+ return ! changed , "new service's annotations does not match the current one:" + reason
727
+ }
728
+
729
+ return true , ""
730
+ }
731
+
675
732
// Update changes Kubernetes objects according to the new specification. Unlike the sync case, the missing object
676
733
// (i.e. service) is treated as an error
677
734
// logical backup cron jobs are an exception: a user-initiated Update can enable a logical backup job
@@ -764,7 +821,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
764
821
updateFailed = true
765
822
return
766
823
}
767
- if syncStatefulSet || ! reflect .DeepEqual (oldSs , newSs ) || ! reflect . DeepEqual ( oldSpec . Annotations , newSpec . Annotations ) {
824
+ if syncStatefulSet || ! reflect .DeepEqual (oldSs , newSs ) {
768
825
c .logger .Debugf ("syncing statefulsets" )
769
826
syncStatefulSet = false
770
827
// TODO: avoid generating the StatefulSet object twice by passing it to syncStatefulSet
0 commit comments