Skip to content

Commit

Permalink
Add test constraint for min k8s version (#50645)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Mattix II <keithmattix@microsoft.com>
Co-authored-by: Keith Mattix II <keithmattix@microsoft.com>
  • Loading branch information
istio-testing and keithmattix committed Apr 23, 2024
1 parent 4e759b6 commit f8a0d0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 30 additions & 12 deletions pkg/test/framework/test.go
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/helm/install_test.go
Expand Up @@ -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' ` +
Expand Down Expand Up @@ -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' ` +
Expand Down

0 comments on commit f8a0d0c

Please sign in to comment.