diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 102b2e763..f62035f7d 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -12,7 +12,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" "strings" "sync" "testing" @@ -50,8 +49,6 @@ var ( commonTestOrgGUID string commonTestOrgName string assetsTmpDir string - clusterVersionMinor int - clusterVersionMajor int defaultAppBitsFile string multiProcessAppBitsFile string ) @@ -1030,9 +1027,6 @@ func commonTestSetup() { appFQDN = helpers.GetRequiredEnvVar("APP_FQDN") - clusterVersionMinor, _ = strconv.Atoi(helpers.GetRequiredEnvVar("CLUSTER_VERSION_MINOR")) - clusterVersionMajor, _ = strconv.Atoi(helpers.GetRequiredEnvVar("CLUSTER_VERSION_MAJOR")) - ensureServerIsUp() serviceAccountFactory = helpers.NewServiceAccountFactory(rootNamespace) diff --git a/tests/e2e/orgs_test.go b/tests/e2e/orgs_test.go index d7d77dd01..edd18a5d4 100644 --- a/tests/e2e/orgs_test.go +++ b/tests/e2e/orgs_test.go @@ -106,6 +106,7 @@ var _ = Describe("Orgs", func() { }) It("doesn't set an HTTP warning header for long certs", func() { + clusterVersionMajor, clusterVersionMinor := helpers.GetClusterVersion() if clusterVersionMajor < 1 || (clusterVersionMajor == 1 && clusterVersionMinor < 22) { GinkgoWriter.Printf("Skipping certificate warning test as k8s v%d.%d doesn't support creation of short lived test client certificates\n", clusterVersionMajor, clusterVersionMinor) return diff --git a/tests/helpers/cert_auth.go b/tests/helpers/cert_auth.go index 3b328660f..384346b42 100644 --- a/tests/helpers/cert_auth.go +++ b/tests/helpers/cert_auth.go @@ -18,7 +18,6 @@ import ( certv1 "k8s.io/api/certificates/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" controllerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -149,11 +148,6 @@ func generateCSR(k8sClient client.Client, key *rsa.PrivateKey, userName string, func approveCSR(csr *certv1.CertificateSigningRequest) { GinkgoHelper() - config, err := controllerruntime.GetConfig() - Expect(err).NotTo(HaveOccurred()) - clientSet, err := kubernetes.NewForConfig(config) - Expect(err).NotTo(HaveOccurred()) - csr.Status.Conditions = append(csr.Status.Conditions, certv1.CertificateSigningRequestCondition{ Type: certv1.RequestConditionType(certv1.CertificateApproved), Status: corev1.ConditionTrue, @@ -162,7 +156,7 @@ func approveCSR(csr *certv1.CertificateSigningRequest) { LastUpdateTime: metav1.Now(), }) - _, err = clientSet.CertificatesV1().CertificateSigningRequests().UpdateApproval( + _, err := getClientSet().CertificatesV1().CertificateSigningRequests().UpdateApproval( context.Background(), csr.Name, csr, diff --git a/tests/helpers/k8s.go b/tests/helpers/k8s.go new file mode 100644 index 000000000..15aab0160 --- /dev/null +++ b/tests/helpers/k8s.go @@ -0,0 +1,41 @@ +package helpers + +import ( + "fmt" + "strconv" + + . "github.com/onsi/ginkgo/v2" //lint:ignore ST1001 this is a test file + . "github.com/onsi/gomega" //lint:ignore ST1001 this is a test file + "k8s.io/client-go/kubernetes" + controllerruntime "sigs.k8s.io/controller-runtime" +) + +func getClientSet() *kubernetes.Clientset { + GinkgoHelper() + + config, err := controllerruntime.GetConfig() + Expect(err).NotTo(HaveOccurred()) + clientSet, err := kubernetes.NewForConfig(config) + Expect(err).NotTo(HaveOccurred()) + + return clientSet +} + +func GetClusterVersion() (int, int) { + GinkgoHelper() + + serverVersion, err := getClientSet().ServerVersion() + Expect(err).NotTo(HaveOccurred()) + + majorVersion, err := strconv.Atoi(serverVersion.Major) + if err != nil { + Skip(fmt.Sprintf("cannot determine kubernetes server major version: %v", err)) + } + + minorVersion, err := strconv.Atoi(serverVersion.Minor) + if err != nil { + Skip(fmt.Sprintf("cannot determine kubernetes server minor version: %v", err)) + } + + return majorVersion, minorVersion +}