@@ -28,6 +28,7 @@ import (
28
28
"github.com/zalando/postgres-operator/pkg/util/users"
29
29
"github.com/zalando/postgres-operator/pkg/util/volumes"
30
30
appsv1 "k8s.io/api/apps/v1"
31
+ batchv1 "k8s.io/api/batch/v1"
31
32
v1 "k8s.io/api/core/v1"
32
33
policyv1 "k8s.io/api/policy/v1"
33
34
rbacv1 "k8s.io/api/rbac/v1"
@@ -438,8 +439,8 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa
438
439
reasons = append (reasons , "new statefulset's persistent volume claim retention policy do not match" )
439
440
}
440
441
441
- needsRollUpdate , reasons = c .compareContainers ("initContainers" , c .Statefulset .Spec .Template .Spec .InitContainers , statefulSet .Spec .Template .Spec .InitContainers , needsRollUpdate , reasons )
442
- needsRollUpdate , reasons = c .compareContainers ("containers" , c .Statefulset .Spec .Template .Spec .Containers , statefulSet .Spec .Template .Spec .Containers , needsRollUpdate , reasons )
442
+ needsRollUpdate , reasons = c .compareContainers ("statefulset initContainers" , c .Statefulset .Spec .Template .Spec .InitContainers , statefulSet .Spec .Template .Spec .InitContainers , needsRollUpdate , reasons )
443
+ needsRollUpdate , reasons = c .compareContainers ("statefulset containers" , c .Statefulset .Spec .Template .Spec .Containers , statefulSet .Spec .Template .Spec .Containers , needsRollUpdate , reasons )
443
444
444
445
if len (c .Statefulset .Spec .Template .Spec .Containers ) == 0 {
445
446
c .logger .Warningf ("statefulset %q has no container" , util .NameFromMeta (c .Statefulset .ObjectMeta ))
@@ -571,30 +572,30 @@ func newCheck(msg string, cond containerCondition) containerCheck {
571
572
572
573
func (c * Cluster ) compareContainers (description string , setA , setB []v1.Container , needsRollUpdate bool , reasons []string ) (bool , []string ) {
573
574
if len (setA ) != len (setB ) {
574
- return true , append (reasons , fmt .Sprintf ("new statefulset %s's length does not match the current ones" , description ))
575
+ return true , append (reasons , fmt .Sprintf ("new %s's length does not match the current ones" , description ))
575
576
}
576
577
577
578
checks := []containerCheck {
578
- newCheck ("new statefulset %s's %s (index %d) name does not match the current one" ,
579
+ newCheck ("new %s's %s (index %d) name does not match the current one" ,
579
580
func (a , b v1.Container ) bool { return a .Name != b .Name }),
580
- newCheck ("new statefulset %s's %s (index %d) readiness probe does not match the current one" ,
581
+ newCheck ("new %s's %s (index %d) readiness probe does not match the current one" ,
581
582
func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .ReadinessProbe , b .ReadinessProbe ) }),
582
- newCheck ("new statefulset %s's %s (index %d) ports do not match the current one" ,
583
+ newCheck ("new %s's %s (index %d) ports do not match the current one" ,
583
584
func (a , b v1.Container ) bool { return ! comparePorts (a .Ports , b .Ports ) }),
584
- newCheck ("new statefulset %s's %s (index %d) resources do not match the current ones" ,
585
+ newCheck ("new %s's %s (index %d) resources do not match the current ones" ,
585
586
func (a , b v1.Container ) bool { return ! compareResources (& a .Resources , & b .Resources ) }),
586
- newCheck ("new statefulset %s's %s (index %d) environment does not match the current one" ,
587
+ newCheck ("new %s's %s (index %d) environment does not match the current one" ,
587
588
func (a , b v1.Container ) bool { return ! compareEnv (a .Env , b .Env ) }),
588
- newCheck ("new statefulset %s's %s (index %d) environment sources do not match the current one" ,
589
+ newCheck ("new %s's %s (index %d) environment sources do not match the current one" ,
589
590
func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .EnvFrom , b .EnvFrom ) }),
590
- newCheck ("new statefulset %s's %s (index %d) security context does not match the current one" ,
591
+ newCheck ("new %s's %s (index %d) security context does not match the current one" ,
591
592
func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .SecurityContext , b .SecurityContext ) }),
592
- newCheck ("new statefulset %s's %s (index %d) volume mounts do not match the current one" ,
593
+ newCheck ("new %s's %s (index %d) volume mounts do not match the current one" ,
593
594
func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .VolumeMounts , b .VolumeMounts ) }),
594
595
}
595
596
596
597
if ! c .OpConfig .EnableLazySpiloUpgrade {
597
- checks = append (checks , newCheck ("new statefulset %s's %s (index %d) image does not match the current one" ,
598
+ checks = append (checks , newCheck ("new %s's %s (index %d) image does not match the current one" ,
598
599
func (a , b v1.Container ) bool { return a .Image != b .Image }))
599
600
}
600
601
@@ -786,6 +787,47 @@ func (c *Cluster) compareServices(old, new *v1.Service) (bool, string) {
786
787
return true , ""
787
788
}
788
789
790
+ func (c * Cluster ) compareLogicalBackupJob (cur , new * batchv1.CronJob ) (match bool , reason string ) {
791
+
792
+ if cur .Spec .Schedule != new .Spec .Schedule {
793
+ return false , fmt .Sprintf ("new job's schedule %q does not match the current one %q" ,
794
+ new .Spec .Schedule , cur .Spec .Schedule )
795
+ }
796
+
797
+ newImage := new .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
798
+ curImage := cur .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Image
799
+ if newImage != curImage {
800
+ return false , fmt .Sprintf ("new job's image %q does not match the current one %q" ,
801
+ newImage , curImage )
802
+ }
803
+
804
+ newPgVersion := getPgVersion (new )
805
+ curPgVersion := getPgVersion (cur )
806
+ if newPgVersion != curPgVersion {
807
+ return false , fmt .Sprintf ("new job's env PG_VERSION %q does not match the current one %q" ,
808
+ newPgVersion , curPgVersion )
809
+ }
810
+
811
+ needsReplace := false
812
+ reasons := make ([]string , 0 )
813
+ needsReplace , reasons = c .compareContainers ("cronjob container" , cur .Spec .JobTemplate .Spec .Template .Spec .Containers , new .Spec .JobTemplate .Spec .Template .Spec .Containers , needsReplace , reasons )
814
+ if needsReplace {
815
+ return false , fmt .Sprintf ("logical backup container specs do not match: %v" , strings .Join (reasons , `', '` ))
816
+ }
817
+
818
+ return true , ""
819
+ }
820
+
821
+ func getPgVersion (cronJob * batchv1.CronJob ) string {
822
+ envs := cronJob .Spec .JobTemplate .Spec .Template .Spec .Containers [0 ].Env
823
+ for _ , env := range envs {
824
+ if env .Name == "PG_VERSION" {
825
+ return env .Value
826
+ }
827
+ }
828
+ return ""
829
+ }
830
+
789
831
// addFinalizer patches the postgresql CR to add finalizer
790
832
func (c * Cluster ) addFinalizer () error {
791
833
if c .hasFinalizer () {
0 commit comments