@@ -30,6 +30,7 @@ import (
30
30
31
31
"github.com/crunchydata/postgres-operator/internal/naming"
32
32
"github.com/crunchydata/postgres-operator/internal/pki"
33
+ "github.com/crunchydata/postgres-operator/internal/util"
33
34
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
34
35
)
35
36
@@ -522,6 +523,7 @@ func TestAddServerToInstancePod(t *testing.T) {
522
523
}
523
524
524
525
t .Run ("CustomResources" , func (t * testing.T ) {
526
+ assert .NilError (t , util .AddAndSetFeatureGates (string (util .TablespaceVolumes + "=false" )))
525
527
cluster := cluster .DeepCopy ()
526
528
cluster .Spec .Backups .PGBackRest .Sidecars = & v1beta1.PGBackRestSidecars {
527
529
PGBackRest : & v1beta1.Sidecar {
@@ -647,6 +649,105 @@ func TestAddServerToInstancePod(t *testing.T) {
647
649
name: instance-secret-name
648
650
` ))
649
651
})
652
+
653
+ t .Run ("AddTablespaces" , func (t * testing.T ) {
654
+ assert .NilError (t , util .AddAndSetFeatureGates (string (util .TablespaceVolumes + "=true" )))
655
+ clusterWithTablespaces := cluster .DeepCopy ()
656
+ clusterWithTablespaces .Spec .InstanceSets = []v1beta1.PostgresInstanceSetSpec {
657
+ {
658
+ TablespaceVolumes : []v1beta1.TablespaceVolume {
659
+ {Name : "trial" },
660
+ {Name : "castle" },
661
+ },
662
+ },
663
+ }
664
+
665
+ out := pod .DeepCopy ()
666
+ out .Volumes = append (out .Volumes , corev1.Volume {Name : "trial" }, corev1.Volume {Name : "castle" })
667
+ AddServerToInstancePod (clusterWithTablespaces , out , "instance-secret-name" )
668
+
669
+ // Only Containers and Volumes fields have changed.
670
+ assert .DeepEqual (t , pod , * out , cmpopts .IgnoreFields (pod , "Containers" , "Volumes" ))
671
+ assert .Assert (t , marshalMatches (out .Containers , `
672
+ - name: database
673
+ resources: {}
674
+ - name: other
675
+ resources: {}
676
+ - command:
677
+ - pgbackrest
678
+ - server
679
+ livenessProbe:
680
+ exec:
681
+ command:
682
+ - pgbackrest
683
+ - server-ping
684
+ name: pgbackrest
685
+ resources: {}
686
+ securityContext:
687
+ allowPrivilegeEscalation: false
688
+ capabilities:
689
+ drop:
690
+ - ALL
691
+ privileged: false
692
+ readOnlyRootFilesystem: true
693
+ runAsNonRoot: true
694
+ volumeMounts:
695
+ - mountPath: /etc/pgbackrest/server
696
+ name: pgbackrest-server
697
+ readOnly: true
698
+ - mountPath: /pgdata
699
+ name: postgres-data
700
+ - mountPath: /pgwal
701
+ name: postgres-wal
702
+ - mountPath: /tablespaces/trial
703
+ name: trial
704
+ - mountPath: /tablespaces/castle
705
+ name: castle
706
+ - command:
707
+ - bash
708
+ - -ceu
709
+ - --
710
+ - |-
711
+ monitor() {
712
+ exec {fd}<> <(:)
713
+ until read -r -t 5 -u "${fd}"; do
714
+ if
715
+ [ "${filename}" -nt "/proc/self/fd/${fd}" ] &&
716
+ pkill -HUP --exact --parent=0 pgbackrest
717
+ then
718
+ exec {fd}>&- && exec {fd}<> <(:)
719
+ stat --dereference --format='Loaded configuration dated %y' "${filename}"
720
+ elif
721
+ { [ "${directory}" -nt "/proc/self/fd/${fd}" ] ||
722
+ [ "${authority}" -nt "/proc/self/fd/${fd}" ]
723
+ } &&
724
+ pkill -HUP --exact --parent=0 pgbackrest
725
+ then
726
+ exec {fd}>&- && exec {fd}<> <(:)
727
+ stat --format='Loaded certificates dated %y' "${directory}"
728
+ fi
729
+ done
730
+ }; export directory="$1" authority="$2" filename="$3"; export -f monitor; exec -a "$0" bash -ceu monitor
731
+ - pgbackrest-config
732
+ - /etc/pgbackrest/server
733
+ - /etc/pgbackrest/conf.d/~postgres-operator/tls-ca.crt
734
+ - /etc/pgbackrest/conf.d/~postgres-operator_server.conf
735
+ name: pgbackrest-config
736
+ resources: {}
737
+ securityContext:
738
+ allowPrivilegeEscalation: false
739
+ capabilities:
740
+ drop:
741
+ - ALL
742
+ privileged: false
743
+ readOnlyRootFilesystem: true
744
+ runAsNonRoot: true
745
+ volumeMounts:
746
+ - mountPath: /etc/pgbackrest/server
747
+ name: pgbackrest-server
748
+ readOnly: true
749
+ ` ))
750
+ })
650
751
}
651
752
652
753
func TestAddServerToRepoPod (t * testing.T ) {
0 commit comments