@@ -21,7 +21,6 @@ package postgrescluster
2121import (
2222 "context"
2323 "errors"
24- "os"
2524 "testing"
2625 "time"
2726
@@ -32,7 +31,9 @@ import (
3231 "k8s.io/apimachinery/pkg/api/resource"
3332 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3433 "k8s.io/apimachinery/pkg/util/validation/field"
34+ "k8s.io/apimachinery/pkg/util/version"
3535 "k8s.io/apimachinery/pkg/util/wait"
36+ "k8s.io/client-go/discovery"
3637 "sigs.k8s.io/controller-runtime/pkg/client"
3738
3839 "github.com/crunchydata/postgres-operator/internal/controller/runtime"
@@ -651,9 +652,18 @@ func TestReconcileConfigureExistingPVCs(t *testing.T) {
651652
652653func TestReconcileMoveDirectories (t * testing.T ) {
653654 ctx := context .Background ()
654- _ , tClient := setupKubernetes (t )
655+ env , tClient := setupKubernetes (t )
655656 require .ParallelCapacity (t , 1 )
656657
658+ dc , err := discovery .NewDiscoveryClientForConfig (env .Config )
659+ assert .NilError (t , err )
660+
661+ server , err := dc .ServerVersion ()
662+ assert .NilError (t , err )
663+
664+ serverVersion , err := version .ParseGeneric (server .GitVersion )
665+ assert .NilError (t , err )
666+
657667 r := & Reconciler {Client : tClient , Owner : client .FieldOwner (t .Name ())}
658668
659669 ns := setupNamespace (t , tClient )
@@ -809,7 +819,7 @@ volumes:
809819 claimName: testpgdata
810820 `
811821
812- if os . Getenv ( "ENVTEST_K8S_VERSION" ) == "1.19.2" {
822+ if serverVersion . LessThan ( version . MustParseGeneric ( "1.20" )) {
813823 compare = `
814824automountServiceAccountToken: false
815825containers:
@@ -921,7 +931,7 @@ volumes:
921931 persistentVolumeClaim:
922932 claimName: testwal
923933 `
924- if os . Getenv ( "ENVTEST_K8S_VERSION" ) == "1.19.2" {
934+ if serverVersion . LessThan ( version . MustParseGeneric ( "1.20" )) {
925935 compare = `
926936automountServiceAccountToken: false
927937containers:
@@ -1036,7 +1046,7 @@ volumes:
10361046 claimName: testrepo
10371047 `
10381048
1039- if os . Getenv ( "ENVTEST_K8S_VERSION" ) == "1.19.2" {
1049+ if serverVersion . LessThan ( version . MustParseGeneric ( "1.20" )) {
10401050 compare = `
10411051automountServiceAccountToken: false
10421052containers:
0 commit comments