Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check kubernetes server version from within the test #2774

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -50,8 +49,6 @@ var (
commonTestOrgGUID string
commonTestOrgName string
assetsTmpDir string
clusterVersionMinor int
clusterVersionMajor int
defaultAppBitsFile string
multiProcessAppBitsFile string
)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions tests/helpers/cert_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions tests/helpers/k8s.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading