@@ -21,6 +21,7 @@ package postgrescluster
2121import (
2222 "context"
2323 "errors"
24+ "os"
2425 "testing"
2526 "time"
2627
@@ -755,7 +756,61 @@ func TestReconcileMoveDirectories(t *testing.T) {
755756
756757 for i := range moveJobs .Items {
757758 if moveJobs .Items [i ].Name == "testcluster-move-pgdata-dir" {
758- assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , `
759+ // TODO(benjaminjb)(issue sc-11672): after we update controller-runtime and
760+ // are no longer testing in Github actions with K8s 1.19.2, reduce the following comparison
761+ // to simply testing against a given, fixed string.
762+
763+ compare := `
764+ automountServiceAccountToken: false
765+ containers:
766+ - command:
767+ - bash
768+ - -ceu
769+ - "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pgdata_pvc=testpgdata\"\n
770+ \ echo \"Current PG data directory volume contents:\" \n ls -lh \"/pgdata\"\n
771+ \ echo \"Now updating PG data directory...\"\n [ -d \"/pgdata/testpgdatadir\"
772+ ] && mv \"/pgdata/testpgdatadir\" \"/pgdata/pg13_bootstrap\"\n rm -f \"/pgdata/pg13/patroni.dynamic.json\"\n
773+ \ echo \"Updated PG data directory contents:\" \n ls -lh \"/pgdata\"\n echo
774+ \"PG Data directory preparation complete\"\n "
775+ image: example.com/crunchy-postgres-ha:test
776+ imagePullPolicy: Always
777+ name: pgdata-move-job
778+ resources:
779+ requests:
780+ cpu: 1m
781+ securityContext:
782+ allowPrivilegeEscalation: false
783+ capabilities:
784+ drop:
785+ - ALL
786+ privileged: false
787+ readOnlyRootFilesystem: true
788+ runAsNonRoot: true
789+ terminationMessagePath: /dev/termination-log
790+ terminationMessagePolicy: File
791+ volumeMounts:
792+ - mountPath: /pgdata
793+ name: postgres-data
794+ dnsPolicy: ClusterFirst
795+ enableServiceLinks: false
796+ imagePullSecrets:
797+ - name: test-secret
798+ priorityClassName: some-priority-class
799+ restartPolicy: Never
800+ schedulerName: default-scheduler
801+ securityContext:
802+ fsGroup: 26
803+ fsGroupChangePolicy: OnRootMismatch
804+ runAsNonRoot: true
805+ terminationGracePeriodSeconds: 30
806+ volumes:
807+ - name: postgres-data
808+ persistentVolumeClaim:
809+ claimName: testpgdata
810+ `
811+
812+ if os .Getenv ("ENVTEST_K8S_VERSION" ) == "1.19.2" {
813+ compare = `
759814automountServiceAccountToken: false
760815containers:
761816- command:
@@ -801,7 +856,10 @@ volumes:
801856- name: postgres-data
802857 persistentVolumeClaim:
803858 claimName: testpgdata
804- ` + "\n " ))
859+ `
860+ }
861+
862+ assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , compare + "\n " ))
805863 }
806864 }
807865
@@ -811,7 +869,60 @@ volumes:
811869
812870 for i := range moveJobs .Items {
813871 if moveJobs .Items [i ].Name == "testcluster-move-pgwal-dir" {
814- assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , `
872+ // TODO(benjaminjb)(issue sc-11672): after we update controller-runtime and
873+ // are no longer testing in Github actions with K8s 1.19.2, reduce the following comparison
874+ // to simply testing against a given, fixed string.
875+
876+ compare := `
877+ automountServiceAccountToken: false
878+ containers:
879+ - command:
880+ - bash
881+ - -ceu
882+ - "echo \"Preparing cluster testcluster volumes for PGO v5.x\"\n echo \"pg_wal_pvc=testwal\"\n
883+ \ echo \"Current PG WAL directory volume contents:\"\n ls -lh \"/pgwal\"\n
884+ \ echo \"Now updating PG WAL directory...\"\n [ -d \"/pgwal/testwaldir\"
885+ ] && mv \"/pgwal/testwaldir\" \"/pgwal/testcluster-wal\"\n echo \"Updated PG
886+ WAL directory contents:\"\n ls -lh \"/pgwal\"\n echo \"PG WAL directory
887+ preparation complete\"\n "
888+ image: example.com/crunchy-postgres-ha:test
889+ imagePullPolicy: Always
890+ name: pgwal-move-job
891+ resources:
892+ requests:
893+ cpu: 1m
894+ securityContext:
895+ allowPrivilegeEscalation: false
896+ capabilities:
897+ drop:
898+ - ALL
899+ privileged: false
900+ readOnlyRootFilesystem: true
901+ runAsNonRoot: true
902+ terminationMessagePath: /dev/termination-log
903+ terminationMessagePolicy: File
904+ volumeMounts:
905+ - mountPath: /pgwal
906+ name: postgres-wal
907+ dnsPolicy: ClusterFirst
908+ enableServiceLinks: false
909+ imagePullSecrets:
910+ - name: test-secret
911+ priorityClassName: some-priority-class
912+ restartPolicy: Never
913+ schedulerName: default-scheduler
914+ securityContext:
915+ fsGroup: 26
916+ fsGroupChangePolicy: OnRootMismatch
917+ runAsNonRoot: true
918+ terminationGracePeriodSeconds: 30
919+ volumes:
920+ - name: postgres-wal
921+ persistentVolumeClaim:
922+ claimName: testwal
923+ `
924+ if os .Getenv ("ENVTEST_K8S_VERSION" ) == "1.19.2" {
925+ compare = `
815926automountServiceAccountToken: false
816927containers:
817928- command:
@@ -857,7 +968,9 @@ volumes:
857968- name: postgres-wal
858969 persistentVolumeClaim:
859970 claimName: testwal
860- ` + "\n " ))
971+ `
972+ }
973+ assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , compare + "\n " ))
861974 }
862975 }
863976
@@ -867,7 +980,64 @@ volumes:
867980
868981 for i := range moveJobs .Items {
869982 if moveJobs .Items [i ].Name == "testcluster-move-pgbackrest-repo-dir" {
870- assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , `
983+
984+ // TODO(benjaminjb)(issue sc-11672): after we update controller-runtime and
985+ // are no longer testing in Github actions with K8s 1.19.2, reduce the following comparison
986+ // to simply testing against a given, fixed string.
987+
988+ compare := `
989+ automountServiceAccountToken: false
990+ containers:
991+ - command:
992+ - bash
993+ - -ceu
994+ - "echo \"Preparing cluster testcluster pgBackRest repo volume for PGO v5.x\"\n
995+ \ echo \"repo_pvc=testrepo\"\n echo \"pgbackrest directory:\"\n ls -lh
996+ /pgbackrest\n echo \"Current pgBackRest repo directory volume contents:\" \n
997+ \ ls -lh \"/pgbackrest/testrepodir\"\n echo \"Now updating repo directory...\"\n
998+ \ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/archive\"\n
999+ \ [ -d \"/pgbackrest/testrepodir\" ] && mv -t \"/pgbackrest/\" \"/pgbackrest/testrepodir/backup\"\n
1000+ \ echo \"Updated /pgbackrest directory contents:\"\n ls -lh \"/pgbackrest\"\n
1001+ \ echo \"Repo directory preparation complete\"\n "
1002+ image: example.com/crunchy-pgbackrest:test
1003+ imagePullPolicy: Always
1004+ name: repo-move-job
1005+ resources:
1006+ requests:
1007+ cpu: 1m
1008+ securityContext:
1009+ allowPrivilegeEscalation: false
1010+ capabilities:
1011+ drop:
1012+ - ALL
1013+ privileged: false
1014+ readOnlyRootFilesystem: true
1015+ runAsNonRoot: true
1016+ terminationMessagePath: /dev/termination-log
1017+ terminationMessagePolicy: File
1018+ volumeMounts:
1019+ - mountPath: /pgbackrest
1020+ name: pgbackrest-repo
1021+ dnsPolicy: ClusterFirst
1022+ enableServiceLinks: false
1023+ imagePullSecrets:
1024+ - name: test-secret
1025+ priorityClassName: some-priority-class
1026+ restartPolicy: Never
1027+ schedulerName: default-scheduler
1028+ securityContext:
1029+ fsGroup: 26
1030+ fsGroupChangePolicy: OnRootMismatch
1031+ runAsNonRoot: true
1032+ terminationGracePeriodSeconds: 30
1033+ volumes:
1034+ - name: pgbackrest-repo
1035+ persistentVolumeClaim:
1036+ claimName: testrepo
1037+ `
1038+
1039+ if os .Getenv ("ENVTEST_K8S_VERSION" ) == "1.19.2" {
1040+ compare = `
8711041automountServiceAccountToken: false
8721042containers:
8731043- command:
@@ -915,7 +1085,9 @@ volumes:
9151085- name: pgbackrest-repo
9161086 persistentVolumeClaim:
9171087 claimName: testrepo
918- ` + "\n " ))
1088+ `
1089+ }
1090+ assert .Assert (t , marshalMatches (moveJobs .Items [i ].Spec .Template .Spec , compare + "\n " ))
9191091 }
9201092 }
9211093
0 commit comments