From ea0cd76fea8395c85a7d9e56c172dd1c47f2ec9c Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Mon, 4 Oct 2021 21:06:09 +0000 Subject: [PATCH 1/2] Upgrade e2e test for latest Kubernetes versions Signed-off-by: Martin Hickey --- test/common.sh | 2 +- test/e2e/local.sh | 2 +- test/e2e/utils/test_context.go | 26 ++++++++++++++----- test/e2e/v2/plugin_cluster_test.go | 24 ++++++++++++----- test/e2e/v3/plugin_cluster_test.go | 16 +++++++++--- .../api/v1/zz_generated.deepcopy.go | 1 - .../apis/crew/v1/zz_generated.deepcopy.go | 1 - .../foo.policy/v1/zz_generated.deepcopy.go | 1 - .../v1beta1/zz_generated.deepcopy.go | 1 - .../v1beta2/zz_generated.deepcopy.go | 1 - .../apis/ship/v1/zz_generated.deepcopy.go | 1 - .../ship/v1beta1/zz_generated.deepcopy.go | 1 - .../ship/v2alpha1/zz_generated.deepcopy.go | 1 - .../api/v1/zz_generated.deepcopy.go | 1 - .../api/v1/zz_generated.deepcopy.go | 1 - .../api/v1/zz_generated.deepcopy.go | 1 - .../apis/crew/v1/zz_generated.deepcopy.go | 1 - .../foo.policy/v1/zz_generated.deepcopy.go | 1 - .../v1beta1/zz_generated.deepcopy.go | 1 - .../v1beta2/zz_generated.deepcopy.go | 1 - .../apis/ship/v1/zz_generated.deepcopy.go | 1 - .../ship/v1beta1/zz_generated.deepcopy.go | 1 - .../ship/v2alpha1/zz_generated.deepcopy.go | 1 - .../apis/v1/zz_generated.deepcopy.go | 1 - .../api/v1/zz_generated.deepcopy.go | 1 - .../api/v1/zz_generated.deepcopy.go | 1 - 26 files changed, 52 insertions(+), 39 deletions(-) diff --git a/test/common.sh b/test/common.sh index 71707d82db1..5d91a279e1d 100644 --- a/test/common.sh +++ b/test/common.sh @@ -27,7 +27,7 @@ if [ -n "$TRACE" ]; then set -x fi -k8s_version=1.16.4 +k8s_version=1.19.2 goarch=amd64 if [[ "$OSTYPE" == "linux-gnu" ]]; then diff --git a/test/e2e/local.sh b/test/e2e/local.sh index 147aeb0884c..b8c77dbbd2d 100755 --- a/test/e2e/local.sh +++ b/test/e2e/local.sh @@ -18,7 +18,7 @@ source "$(dirname "$0")/../common.sh" source "$(dirname "$0")/setup.sh" export KIND_CLUSTER="local-kubebuilder-e2e" -create_cluster ${KIND_K8S_VERSION:-v1.18.15} +create_cluster ${KIND_K8S_VERSION:-v1.22.1} if [ -z "${SKIP_KIND_CLEANUP:-}" ]; then trap delete_cluster EXIT fi diff --git a/test/e2e/utils/test_context.go b/test/e2e/utils/test_context.go index e813b68fa6b..c85b6d03fd6 100644 --- a/test/e2e/utils/test_context.go +++ b/test/e2e/utils/test_context.go @@ -106,7 +106,8 @@ func (t *TestContext) Prepare() error { const ( certmanagerVersionWithv1beta2CRs = "v0.11.0" - certmanagerVersion = "v1.0.4" + certmanagerLegacyVersion = "v1.0.4" + certmanagerVersion = "v1.5.3" certmanagerURLTmplLegacy = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager-legacy.yaml" certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml" @@ -122,7 +123,7 @@ func (t *TestContext) makeCertManagerURL(hasv1beta1CRs bool) string { // Determine which URL to use for a manifest bundle with v1 CRs. // The most up-to-date bundle uses v1 CRDs, which were introduced in k8s v1.16. if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 { - return fmt.Sprintf(certmanagerURLTmplLegacy, certmanagerVersion) + return fmt.Sprintf(certmanagerURLTmplLegacy, certmanagerLegacyVersion) } return fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion) } @@ -158,20 +159,33 @@ func (t *TestContext) UninstallCertManager(hasv1beta1CRs bool) { } const ( - prometheusOperatorVersion = "0.33" - prometheusOperatorURL = "https://raw.githubusercontent.com/coreos/prometheus-operator/release-%s/bundle.yaml" + prometheusOperatorLegacyVersion = "0.33" + prometheusOperatorLegacyURL = "https://raw.githubusercontent.com/coreos/prometheus-operator/release-%s/bundle.yaml" + prometheusOperatorVersion = "0.51" + prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" + + "prometheus-operator/release-%s/bundle.yaml" ) // InstallPrometheusOperManager installs the prometheus manager bundle. func (t *TestContext) InstallPrometheusOperManager() error { - url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + var url string + if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 { + url = fmt.Sprintf(prometheusOperatorLegacyURL, prometheusOperatorLegacyVersion) + } else { + url = fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + } _, err := t.Kubectl.Apply(false, "-f", url) return err } // UninstallPrometheusOperManager uninstalls the prometheus manager bundle. func (t *TestContext) UninstallPrometheusOperManager() { - url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + var url string + if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 { + url = fmt.Sprintf(prometheusOperatorLegacyURL, prometheusOperatorLegacyVersion) + } else { + url = fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion) + } if _, err := t.Kubectl.Delete(false, "-f", url); err != nil { fmt.Fprintf(GinkgoWriter, "error when running kubectl delete during cleaning up prometheus bundle: %v\n", err) } diff --git a/test/e2e/v2/plugin_cluster_test.go b/test/e2e/v2/plugin_cluster_test.go index 13cb11cb7db..5fd38e871cd 100644 --- a/test/e2e/v2/plugin_cluster_test.go +++ b/test/e2e/v2/plugin_cluster_test.go @@ -46,6 +46,12 @@ var _ = Describe("kubebuilder", func() { Expect(err).NotTo(HaveOccurred()) Expect(kbc.Prepare()).To(Succeed()) + // Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 { + Skip(fmt.Sprintf("cluster version %s does not support "+ + "pre v1 CRDs or webhooks", srvVer.GitVersion)) + } + // Install cert-manager with v1beta2 CRs. By("installing cert manager bundle") Expect(kbc.InstallCertManager(true)).To(Succeed()) @@ -58,12 +64,15 @@ var _ = Describe("kubebuilder", func() { By("clean up created API objects during test process") kbc.CleanupManifests(filepath.Join("config", "default")) - By("uninstalling prometheus manager bundle") - kbc.UninstallPrometheusOperManager() + // Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 22 { + By("uninstalling prometheus manager bundle") + kbc.UninstallPrometheusOperManager() - // Uninstall cert-manager with v1beta2 CRs. - By("uninstalling cert manager bundle") - kbc.UninstallCertManager(true) + // Uninstall cert-manager with v1beta2 CRs. + By("uninstalling cert manager bundle") + kbc.UninstallCertManager(true) + } By("remove container image and work dir") kbc.Destroy() @@ -218,8 +227,9 @@ var _ = Describe("kubebuilder", func() { By("creating a pod with curl image") cmdOpts := []string{ - "run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--", - "curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token), + "run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--", + "curl", "-v", "-k", "-H", + fmt.Sprintf(`Authorization: Bearer %s`, token), fmt.Sprintf("https://e2e-%v-controller-manager-metrics-service.e2e-%v-system.svc:8443/metrics", kbc.TestSuffix, kbc.TestSuffix), } diff --git a/test/e2e/v3/plugin_cluster_test.go b/test/e2e/v3/plugin_cluster_test.go index 014a6233389..a129abe2c42 100644 --- a/test/e2e/v3/plugin_cluster_test.go +++ b/test/e2e/v3/plugin_cluster_test.go @@ -68,10 +68,18 @@ var _ = Describe("kubebuilder", func() { Context("plugin go.kubebuilder.io/v2", func() { // Use cert-manager with v1beta2 CRs. BeforeEach(func() { + // Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 { + Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion)) + } By("installing the v1beta2 cert-manager bundle") Expect(kbc.InstallCertManager(true)).To(Succeed()) }) AfterEach(func() { + // Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 { + Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion)) + } By("uninstalling the v1beta2 cert-manager bundle") kbc.UninstallCertManager(true) }) @@ -109,7 +117,9 @@ var _ = Describe("kubebuilder", func() { }) It("should generate a runnable project with v1beta1 CRDs and Webhooks", func() { // Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field. - if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 { + // Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 || + srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 { Skip(fmt.Sprintf("cluster version %s does not support project defaults", srvVer.GitVersion)) } @@ -307,7 +317,7 @@ func curlMetrics(kbc *utils.TestContext) string { By("creating a curl pod") cmdOpts := []string{ - "run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", + "run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--serviceaccount=" + kbc.Kubectl.ServiceAccount, "--", "curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token), fmt.Sprintf("https://e2e-%s-controller-manager-metrics-service.%s.svc:8443/metrics", @@ -328,7 +338,7 @@ func curlMetrics(kbc *utils.TestContext) string { } return nil } - EventuallyWithOffset(2, verifyCurlUp, 30*time.Second, time.Second).Should(Succeed()) + EventuallyWithOffset(2, verifyCurlUp, 240*time.Second, time.Second).Should(Succeed()) By("validating that the metrics endpoint is serving as expected") var metricsOutput string diff --git a/testdata/project-v2-addon/api/v1/zz_generated.deepcopy.go b/testdata/project-v2-addon/api/v1/zz_generated.deepcopy.go index 1e0ee99b098..2c7ff18b02a 100644 --- a/testdata/project-v2-addon/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2-addon/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go index 79eef5e9930..dc8e3791ad0 100644 --- a/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/crew/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go index bef6e3c6000..a60d7e6746e 100644 --- a/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go index 71feb8c5ac4..e25c50ce9ec 100644 --- a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go index 1614cf756bd..d5897d6f283 100644 --- a/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go index 6d46917d7c7..7eafe038015 100644 --- a/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/ship/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go index 9049045ef1f..00fe91f2c62 100644 --- a/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go index d2ea7f25efb..e7e42679f78 100644 --- a/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go +++ b/testdata/project-v2-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v2/api/v1/zz_generated.deepcopy.go b/testdata/project-v2/api/v1/zz_generated.deepcopy.go index 124ca48a26d..aa7f8f665cc 100644 --- a/testdata/project-v2/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v2/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-addon/api/v1/zz_generated.deepcopy.go b/testdata/project-v3-addon/api/v1/zz_generated.deepcopy.go index 1e0ee99b098..2c7ff18b02a 100644 --- a/testdata/project-v3-addon/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-addon/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-config/api/v1/zz_generated.deepcopy.go b/testdata/project-v3-config/api/v1/zz_generated.deepcopy.go index 124ca48a26d..aa7f8f665cc 100644 --- a/testdata/project-v3-config/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-config/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/crew/v1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/crew/v1/zz_generated.deepcopy.go index 79eef5e9930..dc8e3791ad0 100644 --- a/testdata/project-v3-multigroup/apis/crew/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/crew/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go index bef6e3c6000..a60d7e6746e 100644 --- a/testdata/project-v3-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go index 71feb8c5ac4..e25c50ce9ec 100644 --- a/testdata/project-v3-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go index 1614cf756bd..d5897d6f283 100644 --- a/testdata/project-v3-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/ship/v1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/ship/v1/zz_generated.deepcopy.go index 6d46917d7c7..7eafe038015 100644 --- a/testdata/project-v3-multigroup/apis/ship/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/ship/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go index 9049045ef1f..00fe91f2c62 100644 --- a/testdata/project-v3-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go index d2ea7f25efb..e7e42679f78 100644 --- a/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-multigroup/apis/v1/zz_generated.deepcopy.go b/testdata/project-v3-multigroup/apis/v1/zz_generated.deepcopy.go index 3ad02a2c4fe..b9e0e7ed74f 100644 --- a/testdata/project-v3-multigroup/apis/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-multigroup/apis/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3-v1beta1/api/v1/zz_generated.deepcopy.go b/testdata/project-v3-v1beta1/api/v1/zz_generated.deepcopy.go index d4d73fe7926..05f58c4da6d 100644 --- a/testdata/project-v3-v1beta1/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3-v1beta1/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/testdata/project-v3/api/v1/zz_generated.deepcopy.go b/testdata/project-v3/api/v1/zz_generated.deepcopy.go index 124ca48a26d..aa7f8f665cc 100644 --- a/testdata/project-v3/api/v1/zz_generated.deepcopy.go +++ b/testdata/project-v3/api/v1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* From 7e7b938b41c44b5cc11a18793d5b878b9e836ab7 Mon Sep 17 00:00:00 2001 From: Martin Hickey Date: Mon, 11 Oct 2021 09:57:59 +0000 Subject: [PATCH 2/2] Update the Kind version kind v0.11.0+ supports Kubernetes 1.20+ Signed-off-by: Martin Hickey --- test/common.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/common.sh b/test/common.sh index 5d91a279e1d..2bdc79e0ca8 100644 --- a/test/common.sh +++ b/test/common.sh @@ -28,6 +28,7 @@ if [ -n "$TRACE" ]; then fi k8s_version=1.19.2 +kind_version=0.11.1 goarch=amd64 if [[ "$OSTYPE" == "linux-gnu" ]]; then @@ -105,14 +106,31 @@ function fetch_tools { export KUBEBUILDER_ASSETS=$kb_root_dir/bin/ } +# Check if version of tool is less than or equal a required version +function is_ver_lessthanequal { + [ "$1" = "`echo -e \"$1\n$2\" | sort -V | head -n1`" ] +} + +# Check if version of tool is less than a required version +function is_ver_lessthan { + [ "$1" = "$2" ] && return 1 || is_ver_lessthanequal $1 $2 +} + # Installing kind in a temporal dir if no previously installed function install_kind { header_text "Checking if kind is installed" if ! is_installed kind ; then header_text "Kind not found, installing kind" pushd $(mktemp -d) - GO111MODULE=on go get sigs.k8s.io/kind@v0.7.0 + GO111MODULE=on go get sigs.k8s.io/kind@v$kind_version popd + else + if is_ver_lessthan `kind version -q` $kind_version ; then + header_text "Kind version less than v$kind_version, updating kind" + pushd $(mktemp -d) + GO111MODULE=on go get sigs.k8s.io/kind@v$kind_version + popd + fi fi } @@ -123,3 +141,4 @@ function is_installed { fi return 1 } +