From f8a0d0cc9f4f1dd93cae18e4490bc0ace99516ab Mon Sep 17 00:00:00 2001 From: Istio Automation Date: Tue, 23 Apr 2024 15:52:12 -0700 Subject: [PATCH] Add test constraint for min k8s version (#50645) Signed-off-by: Keith Mattix II Co-authored-by: Keith Mattix II --- pkg/test/framework/test.go | 42 ++++++++++++++++++-------- tests/integration/helm/install_test.go | 2 ++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/pkg/test/framework/test.go b/pkg/test/framework/test.go index e78e11d7c91f..c133d3de5dd4 100644 --- a/pkg/test/framework/test.go +++ b/pkg/test/framework/test.go @@ -31,10 +31,12 @@ import ( type Test interface { // Label applies the given labels to this test. Label(labels ...label.Instance) Test - // Label applies the given labels to this test. // RequireIstioVersion ensures that all installed versions of Istio are at least the // required version for the annotated test to pass RequireIstioVersion(version string) Test + // RequireKubernetesMinorVersion ensures that all Kubernetes clusters used in this test + // are at least the required version for the annotated test to pass + RequireKubernetesMinorVersion(minorVersion uint) Test // RequiresMinClusters ensures that the current environment contains at least the expected number of clusters. // Otherwise it stops test execution and skips the test. // @@ -109,17 +111,18 @@ type Test interface { // Test allows the test author to specify test-related metadata in a fluent-style, before commencing execution. type testImpl struct { // name to be used when creating a Golang test. Only used for subtests. - name string - parent *testImpl - goTest *testing.T - labels []label.Instance - s *suiteContext - requiredMinClusters int - requiredMaxClusters int - requireLocalIstiod bool - requireSingleNetwork bool - minIstioVersion string - topLevel bool + name string + parent *testImpl + goTest *testing.T + labels []label.Instance + s *suiteContext + requiredMinClusters int + requiredMaxClusters int + requireLocalIstiod bool + requireSingleNetwork bool + minIstioVersion string + minKubernetesMinorVersion uint + topLevel bool ctx *testContext tc context2.Context @@ -183,6 +186,11 @@ func (t *testImpl) RequireIstioVersion(version string) Test { return t } +func (t *testImpl) RequireKubernetesMinorVersion(minorVersion uint) Test { + t.minKubernetesMinorVersion = minorVersion + return t +} + func (t *testImpl) Run(fn func(ctx TestContext)) { t.runInternal(fn, false) } @@ -242,6 +250,16 @@ func (t *testImpl) doRun(ctx *testContext, fn func(ctx TestContext), parallel bo return } + if t.minKubernetesMinorVersion > 0 { + for _, c := range ctx.Clusters() { + if !c.MinKubeVersion(t.minKubernetesMinorVersion) { + t.goTest.Skipf("Skipping %q: cluster %s is below required min k8s version 1.%d", + t.goTest.Name(), c.Name(), t.minKubernetesMinorVersion) + return + } + } + } + if t.requireLocalIstiod { for _, c := range ctx.Clusters() { if !c.IsPrimary() { diff --git a/tests/integration/helm/install_test.go b/tests/integration/helm/install_test.go index 847db02a3b8d..0976695edbab 100644 --- a/tests/integration/helm/install_test.go +++ b/tests/integration/helm/install_test.go @@ -101,6 +101,7 @@ profile: stable framework. NewTest(t). + RequireKubernetesMinorVersion(30). Run(setupInstallationWithCustomCheck(overrideValuesStr, false, DefaultNamespaceConfig, func(t framework.TestContext) { // Try to apply an EnvoyFilter (it should be rejected) expectedErrorPrefix := `%s "sample" is forbidden: ValidatingAdmissionPolicy 'stable-channel-default-policy.istio.io' ` + @@ -143,6 +144,7 @@ defaultRevision: "" revision := "1-x" framework. NewTest(t). + RequireKubernetesMinorVersion(30). Run(setupInstallationWithCustomCheck(overrideValuesStr, false, DefaultNamespaceConfig, func(t framework.TestContext) { // Try to apply an EnvoyFilter (it should be rejected) expectedErrorPrefix := `%s "sample" is forbidden: ValidatingAdmissionPolicy 'stable-channel-policy-1-x-istio-system.istio.io' ` +