From f2d34426f8691a72fca2e462b07791299dce1282 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 19 Jun 2023 17:13:37 +0200 Subject: [PATCH] e2e: enhance SIGDescribe framework.SIGDescribe is better because: - Ginkgo uses the source code location of the test, not of the wrapper, when reporting progress. - Additional annotations can be passed. To make this a drop-in replacement, framework.SIGDescribe generates a function that can be used instead of the former SIGDescribe functions. windows.SIGDescribe contained some additional code to ensure that tests are skipped when not running with a suitable node OS. This gets moved into a separate wrapper generator, to allow using framework.SIGDescribe as intended. To ensure that all callers were modified, the windows.sigDescribe isn't exported anymore (wasn't necessary in the first place!). --- test/e2e/README.md | 6 ++---- test/e2e/apimachinery/framework.go | 6 ++---- test/e2e/apps/framework.go | 6 ++---- test/e2e/architecture/framework.go | 6 ++---- test/e2e/auth/framework.go | 6 ++---- test/e2e/autoscaling/framework.go | 6 ++---- test/e2e/cloud/framework.go | 6 ++---- test/e2e/cloud/gcp/apps/framework.go | 6 ++---- test/e2e/cloud/gcp/auth/framework.go | 6 ++---- test/e2e/cloud/gcp/framework.go | 6 ++---- test/e2e/cloud/gcp/network/framework.go | 6 ++---- test/e2e/cloud/gcp/node/framework.go | 6 ++---- test/e2e/common/network/framework.go | 6 ++---- test/e2e/common/node/framework.go | 7 ++----- test/e2e/common/storage/framework.go | 6 ++---- test/e2e/framework/ginkgowrapper.go | 21 +++++++++++++++++++ .../framework/internal/unittests/bugs/bugs.go | 7 ++++--- test/e2e/instrumentation/common/framework.go | 6 ++---- test/e2e/kubectl/framework.go | 6 ++---- test/e2e/lifecycle/framework.go | 6 ++---- test/e2e/network/common/framework.go | 6 ++---- test/e2e/node/framework.go | 6 ++---- test/e2e/scheduling/framework.go | 10 +++------ test/e2e/storage/utils/framework.go | 6 ++---- test/e2e/windows/cpu_limits.go | 4 ++-- test/e2e/windows/density.go | 4 ++-- test/e2e/windows/device_plugin.go | 4 ++-- test/e2e/windows/dns.go | 4 ++-- test/e2e/windows/framework.go | 20 +++++++++++++----- test/e2e/windows/gmsa_full.go | 4 ++-- test/e2e/windows/gmsa_kubelet.go | 4 ++-- test/e2e/windows/host_process.go | 4 ++-- test/e2e/windows/hybrid_network.go | 4 ++-- test/e2e/windows/hyperv.go | 4 ++-- test/e2e/windows/kubelet_stats.go | 9 ++++---- test/e2e/windows/memory_limits.go | 5 ++--- test/e2e/windows/reboot_node.go | 4 ++-- test/e2e/windows/security_context.go | 4 ++-- test/e2e/windows/service.go | 5 ++--- test/e2e/windows/volumes.go | 5 ++--- test/e2e_node/framework.go | 6 ++---- 41 files changed, 120 insertions(+), 139 deletions(-) diff --git a/test/e2e/README.md b/test/e2e/README.md index bef1f2cbff2..656c86eceec 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -45,12 +45,10 @@ import ( // test/e2e/lifecycle/framework.go package lifecycle -import "github.com/onsi/ginkgo" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-cluster-lifecycle] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("cluster-lifecycle") ``` ```golang // test/e2e/lifecycle/bootstrap/bootstrap_signer.go diff --git a/test/e2e/apimachinery/framework.go b/test/e2e/apimachinery/framework.go index 6b7ee59a919..4edc3411949 100644 --- a/test/e2e/apimachinery/framework.go +++ b/test/e2e/apimachinery/framework.go @@ -16,9 +16,7 @@ limitations under the License. package apimachinery -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-api-machinery] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("api-machinery") diff --git a/test/e2e/apps/framework.go b/test/e2e/apps/framework.go index dde7fa0326b..d940e5f1f2f 100644 --- a/test/e2e/apps/framework.go +++ b/test/e2e/apps/framework.go @@ -16,9 +16,7 @@ limitations under the License. package apps -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-apps] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("apps") diff --git a/test/e2e/architecture/framework.go b/test/e2e/architecture/framework.go index 4d7d819c006..b8b12b950a6 100644 --- a/test/e2e/architecture/framework.go +++ b/test/e2e/architecture/framework.go @@ -16,9 +16,7 @@ limitations under the License. package architecture -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-architecture] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("architecture") diff --git a/test/e2e/auth/framework.go b/test/e2e/auth/framework.go index cf3d006234b..0c0e3bc8408 100644 --- a/test/e2e/auth/framework.go +++ b/test/e2e/auth/framework.go @@ -16,9 +16,7 @@ limitations under the License. package auth -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-auth] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("auth") diff --git a/test/e2e/autoscaling/framework.go b/test/e2e/autoscaling/framework.go index 0392976c4cc..5dd080ee845 100644 --- a/test/e2e/autoscaling/framework.go +++ b/test/e2e/autoscaling/framework.go @@ -16,9 +16,7 @@ limitations under the License. package autoscaling -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-autoscaling] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("autoscaling") diff --git a/test/e2e/cloud/framework.go b/test/e2e/cloud/framework.go index 1d80fbbc937..8eb4e55409d 100644 --- a/test/e2e/cloud/framework.go +++ b/test/e2e/cloud/framework.go @@ -16,9 +16,7 @@ limitations under the License. package cloud -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-cloud-provider] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("cloud-provider") diff --git a/test/e2e/cloud/gcp/apps/framework.go b/test/e2e/cloud/gcp/apps/framework.go index 5f2edc490e2..7e768e42a2b 100644 --- a/test/e2e/cloud/gcp/apps/framework.go +++ b/test/e2e/cloud/gcp/apps/framework.go @@ -16,9 +16,7 @@ limitations under the License. package apps -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-apps] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("apps") diff --git a/test/e2e/cloud/gcp/auth/framework.go b/test/e2e/cloud/gcp/auth/framework.go index 8245c662f04..f0b0298eb73 100644 --- a/test/e2e/cloud/gcp/auth/framework.go +++ b/test/e2e/cloud/gcp/auth/framework.go @@ -16,9 +16,7 @@ limitations under the License. package auth -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-auth] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("auth") diff --git a/test/e2e/cloud/gcp/framework.go b/test/e2e/cloud/gcp/framework.go index edd24776ca6..abe47298dab 100644 --- a/test/e2e/cloud/gcp/framework.go +++ b/test/e2e/cloud/gcp/framework.go @@ -16,9 +16,7 @@ limitations under the License. package gcp -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-cloud-provider-gcp] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("cloud-provider-gcp") diff --git a/test/e2e/cloud/gcp/network/framework.go b/test/e2e/cloud/gcp/network/framework.go index 3e3e946d9f7..055cfa3675b 100644 --- a/test/e2e/cloud/gcp/network/framework.go +++ b/test/e2e/cloud/gcp/network/framework.go @@ -16,9 +16,7 @@ limitations under the License. package network -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-network] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("network") diff --git a/test/e2e/cloud/gcp/node/framework.go b/test/e2e/cloud/gcp/node/framework.go index b40fd35c8ca..7a7ee5d5297 100644 --- a/test/e2e/cloud/gcp/node/framework.go +++ b/test/e2e/cloud/gcp/node/framework.go @@ -16,9 +16,7 @@ limitations under the License. package node -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-node] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("node") diff --git a/test/e2e/common/network/framework.go b/test/e2e/common/network/framework.go index 3e3e946d9f7..055cfa3675b 100644 --- a/test/e2e/common/network/framework.go +++ b/test/e2e/common/network/framework.go @@ -16,9 +16,7 @@ limitations under the License. package network -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-network] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("network") diff --git a/test/e2e/common/node/framework.go b/test/e2e/common/node/framework.go index b40fd35c8ca..884f4bf48bf 100644 --- a/test/e2e/common/node/framework.go +++ b/test/e2e/common/node/framework.go @@ -16,9 +16,6 @@ limitations under the License. package node -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" -// SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-node] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("node") diff --git a/test/e2e/common/storage/framework.go b/test/e2e/common/storage/framework.go index d3351a06ff2..a7967e83aac 100644 --- a/test/e2e/common/storage/framework.go +++ b/test/e2e/common/storage/framework.go @@ -16,9 +16,7 @@ limitations under the License. package storage -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-storage] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("storage") diff --git a/test/e2e/framework/ginkgowrapper.go b/test/e2e/framework/ginkgowrapper.go index 5826f7885c5..ed7b9432f05 100644 --- a/test/e2e/framework/ginkgowrapper.go +++ b/test/e2e/framework/ginkgowrapper.go @@ -20,6 +20,7 @@ import ( "fmt" "path" "reflect" + "regexp" "strings" "github.com/onsi/ginkgo/v2" @@ -123,6 +124,26 @@ func AnnotatedLocationWithOffset(annotation string, offset int) types.CodeLocati return codeLocation } +// SIGDescribe returns a wrapper function for ginkgo.Describe which injects +// the SIG name as annotation. The parameter should be lowercase with +// no spaces and no sig- or SIG- prefix. +func SIGDescribe(sig string) func(string, ...interface{}) bool { + if !sigRE.MatchString(sig) || strings.HasPrefix(sig, "sig-") { + panic(fmt.Sprintf("SIG label must be lowercase, no spaces and no sig- prefix, got instead: %q", sig)) + } + return func(text string, args ...interface{}) bool { + args = append(args, ginkgo.Label("sig-"+sig)) + if text == "" { + text = fmt.Sprintf("[sig-%s]", sig) + } else { + text = fmt.Sprintf("[sig-%s] %s", sig, text) + } + return registerInSuite(ginkgo.Describe, text, args) + } +} + +var sigRE = regexp.MustCompile(`^[a-z]+(-[a-z]+)*$`) + // ConformanceIt is wrapper function for ginkgo It. Adds "[Conformance]" tag and makes static analysis easier. func ConformanceIt(text string, args ...interface{}) bool { args = append(args, ginkgo.Offset(1), WithConformance()) diff --git a/test/e2e/framework/internal/unittests/bugs/bugs.go b/test/e2e/framework/internal/unittests/bugs/bugs.go index 842aab8f8da..e84d04d638d 100644 --- a/test/e2e/framework/internal/unittests/bugs/bugs.go +++ b/test/e2e/framework/internal/unittests/bugs/bugs.go @@ -69,7 +69,7 @@ var ( func Describe() { // Normally a single line would be better, but this is an extreme example and // thus uses multiple. - framework.Describe("abc", + framework.SIGDescribe("testing")("abc", // Bugs in parameters will be attributed to the Describe call, not the line of the parameter. "", // buggy: not needed " space1", // buggy: leading white space @@ -123,8 +123,8 @@ ERROR: some/relative/path/buggy.go:200: with spaces ` // Used by unittests/list-tests. It's sorted by test name, not source code location. ListTestsOutput = `The following spec names can be used with 'ginkgo run --focus/skip': - ../bugs/bugs.go:103: abc space1 space2 [Feature: no-such-feature] [Feature: feature-foo] [Environment: no-such-env] [Environment: Linux] [no-such-node-env] [node-feature-foo] [FeatureGate: no-such-feature-gate] [FeatureGate: TestAlphaFeature] [Alpha] [FeatureGate: TestBetaFeature] [Beta] [FeatureGate: TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz x [foo] should [bar] - ../bugs/bugs.go:98: abc space1 space2 [Feature: no-such-feature] [Feature: feature-foo] [Environment: no-such-env] [Environment: Linux] [no-such-node-env] [node-feature-foo] [FeatureGate: no-such-feature-gate] [FeatureGate: TestAlphaFeature] [Alpha] [FeatureGate: TestBetaFeature] [Beta] [FeatureGate: TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz y [foo] should [bar] + ../bugs/bugs.go:103: [sig-testing] abc space1 space2 [Feature: no-such-feature] [Feature: feature-foo] [Environment: no-such-env] [Environment: Linux] [no-such-node-env] [node-feature-foo] [FeatureGate: no-such-feature-gate] [FeatureGate: TestAlphaFeature] [Alpha] [FeatureGate: TestBetaFeature] [Beta] [FeatureGate: TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz x [foo] should [bar] + ../bugs/bugs.go:98: [sig-testing] abc space1 space2 [Feature: no-such-feature] [Feature: feature-foo] [Environment: no-such-env] [Environment: Linux] [no-such-node-env] [node-feature-foo] [FeatureGate: no-such-feature-gate] [FeatureGate: TestAlphaFeature] [Alpha] [FeatureGate: TestBetaFeature] [Beta] [FeatureGate: TestGAFeature] [Conformance] [NodeConformance] [Slow] [Serial] [Disruptive] [custom-label] xyz y [foo] should [bar] ` @@ -150,6 +150,7 @@ ERROR: some/relative/path/buggy.go:200: with spaces foo no-such-node-env node-feature-foo + sig-testing ` ) diff --git a/test/e2e/instrumentation/common/framework.go b/test/e2e/instrumentation/common/framework.go index a7386091378..7b557d993f1 100644 --- a/test/e2e/instrumentation/common/framework.go +++ b/test/e2e/instrumentation/common/framework.go @@ -16,9 +16,7 @@ limitations under the License. package common -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-instrumentation] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("instrumentation") diff --git a/test/e2e/kubectl/framework.go b/test/e2e/kubectl/framework.go index 1b95893fb2c..bfb1b95d902 100644 --- a/test/e2e/kubectl/framework.go +++ b/test/e2e/kubectl/framework.go @@ -16,9 +16,7 @@ limitations under the License. package kubectl -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-cli] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("cli") diff --git a/test/e2e/lifecycle/framework.go b/test/e2e/lifecycle/framework.go index 97026c000ff..c697880ce66 100644 --- a/test/e2e/lifecycle/framework.go +++ b/test/e2e/lifecycle/framework.go @@ -16,9 +16,7 @@ limitations under the License. package lifecycle -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-cluster-lifecycle] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("cluster-lifecycle") diff --git a/test/e2e/network/common/framework.go b/test/e2e/network/common/framework.go index b4c77ecfaf0..6efe22e2735 100644 --- a/test/e2e/network/common/framework.go +++ b/test/e2e/network/common/framework.go @@ -16,9 +16,7 @@ limitations under the License. package common -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-network] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("network") diff --git a/test/e2e/node/framework.go b/test/e2e/node/framework.go index eb2a1bb9e7c..126d2d3a8a4 100644 --- a/test/e2e/node/framework.go +++ b/test/e2e/node/framework.go @@ -16,9 +16,7 @@ limitations under the License. package node -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-node] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("node") diff --git a/test/e2e/scheduling/framework.go b/test/e2e/scheduling/framework.go index 507820094d7..20ef5b180e9 100644 --- a/test/e2e/scheduling/framework.go +++ b/test/e2e/scheduling/framework.go @@ -21,8 +21,6 @@ import ( "fmt" "time" - "github.com/onsi/ginkgo/v2" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" @@ -33,12 +31,10 @@ import ( var ( timeout = 10 * time.Minute waitTime = 2 * time.Second -) -// SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-scheduling] "+text, body) -} + // SIGDescribe annotates the test with the SIG label. + SIGDescribe = framework.SIGDescribe("scheduling") +) // WaitForStableCluster waits until all existing pods are scheduled and returns their amount. func WaitForStableCluster(c clientset.Interface, workerNodes sets.Set[string]) int { diff --git a/test/e2e/storage/utils/framework.go b/test/e2e/storage/utils/framework.go index 7bd007044f2..2257e03287c 100644 --- a/test/e2e/storage/utils/framework.go +++ b/test/e2e/storage/utils/framework.go @@ -16,9 +16,7 @@ limitations under the License. package utils -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-storage] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("storage") diff --git a/test/e2e/windows/cpu_limits.go b/test/e2e/windows/cpu_limits.go index 3e7003c4018..bc799af3d04 100644 --- a/test/e2e/windows/cpu_limits.go +++ b/test/e2e/windows/cpu_limits.go @@ -35,7 +35,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] Cpu Resources [Serial]", func() { +var _ = sigDescribe("[Feature:Windows] Cpu Resources [Serial]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("cpu-resources-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -100,7 +100,7 @@ var _ = SIGDescribe("[Feature:Windows] Cpu Resources [Serial]", func() { } }) }) -}) +})) // newCPUBurnPods creates a list of pods (specification) with a workload that will consume all available CPU resources up to container limit func newCPUBurnPods(numPods int, image imageutils.Config, cpuLimit string, memoryLimit string) []*v1.Pod { diff --git a/test/e2e/windows/density.go b/test/e2e/windows/density.go index b344b663e34..ceb98cbf5c3 100644 --- a/test/e2e/windows/density.go +++ b/test/e2e/windows/density.go @@ -40,7 +40,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] Density [Serial] [Slow]", func() { +var _ = sigDescribe("[Feature:Windows] Density [Serial] [Slow]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("density-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -72,7 +72,7 @@ var _ = SIGDescribe("[Feature:Windows] Density [Serial] [Slow]", func() { } }) -}) +})) type densityTest struct { // number of pods diff --git a/test/e2e/windows/device_plugin.go b/test/e2e/windows/device_plugin.go index dfcaa0babb1..416e1969a74 100644 --- a/test/e2e/windows/device_plugin.go +++ b/test/e2e/windows/device_plugin.go @@ -39,7 +39,7 @@ const ( testSlowMultiplier = 60 ) -var _ = SIGDescribe("[Feature:GPUDevicePlugin] Device Plugin", func() { +var _ = sigDescribe("[Feature:GPUDevicePlugin] Device Plugin", skipUnlessWindows(func() { f := framework.NewDefaultFramework("device-plugin") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -132,4 +132,4 @@ var _ = SIGDescribe("[Feature:GPUDevicePlugin] Device Plugin", func() { _, envVarDirectxGpuNameErr := e2eoutput.LookForStringInPodExec(defaultNs, windowsPod.Name, envVarCommand, envVarDirectxGpuName, time.Minute) framework.ExpectNoError(envVarDirectxGpuNameErr, "failed: didn't find expected environment variable.") }) -}) +})) diff --git a/test/e2e/windows/dns.go b/test/e2e/windows/dns.go index bb2dcaadc3b..a9de7723076 100644 --- a/test/e2e/windows/dns.go +++ b/test/e2e/windows/dns.go @@ -31,7 +31,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] DNS", func() { +var _ = sigDescribe("[Feature:Windows] DNS", skipUnlessWindows(func() { ginkgo.BeforeEach(func() { e2eskipper.SkipUnlessNodeOSDistroIs("windows") @@ -136,4 +136,4 @@ var _ = SIGDescribe("[Feature:Windows] DNS", func() { // TODO: Add more test cases for other DNSPolicies. }) -}) +})) diff --git a/test/e2e/windows/framework.go b/test/e2e/windows/framework.go index a0ec0cabcd9..dd9bcc396cb 100644 --- a/test/e2e/windows/framework.go +++ b/test/e2e/windows/framework.go @@ -17,19 +17,29 @@ limitations under the License. package windows import ( + "k8s.io/kubernetes/test/e2e/framework" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" "github.com/onsi/ginkgo/v2" ) -// SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-windows] "+text, func() { +// sigDescribe annotates the test with the SIG label. +// Use this together with skipUnlessWindows to define +// tests that only run if the node OS is Windows: +// +// sigDescribe("foo", skipUnlessWindows(func() { ... })) +var sigDescribe = framework.SIGDescribe("windows") + +// skipUnlessWindows wraps some other Ginkgo callback such that +// a BeforeEach runs before tests defined by that callback which +// skips those tests unless the node OS is Windows. +func skipUnlessWindows(cb func()) func() { + return func() { ginkgo.BeforeEach(func() { // all tests in this package are Windows specific e2eskipper.SkipUnlessNodeOSDistroIs("windows") }) - body() - }) + cb() + } } diff --git a/test/e2e/windows/gmsa_full.go b/test/e2e/windows/gmsa_full.go index 100c0dde0d2..2a3f94a98d1 100644 --- a/test/e2e/windows/gmsa_full.go +++ b/test/e2e/windows/gmsa_full.go @@ -90,7 +90,7 @@ const ( gmsaSharedFolder = "write_test" ) -var _ = SIGDescribe("[Feature:Windows] GMSA Full [Serial] [Slow]", func() { +var _ = sigDescribe("[Feature:Windows] GMSA Full [Serial] [Slow]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("gmsa-full-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -220,7 +220,7 @@ var _ = SIGDescribe("[Feature:Windows] GMSA Full [Serial] [Slow]", func() { }) }) -}) +})) func isValidOutput(output string) bool { return strings.Contains(output, expectedQueryOutput) && diff --git a/test/e2e/windows/gmsa_kubelet.go b/test/e2e/windows/gmsa_kubelet.go index e6fe25c14f6..a7d041fcd97 100644 --- a/test/e2e/windows/gmsa_kubelet.go +++ b/test/e2e/windows/gmsa_kubelet.go @@ -39,7 +39,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] GMSA Kubelet [Slow]", func() { +var _ = sigDescribe("[Feature:Windows] GMSA Kubelet [Slow]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("gmsa-kubelet-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -133,7 +133,7 @@ var _ = SIGDescribe("[Feature:Windows] GMSA Kubelet [Slow]", func() { }) }) }) -}) +})) func generateDummyCredSpecs(domain string) *string { shortName := strings.ToUpper(strings.Split(domain, ".")[0]) diff --git a/test/e2e/windows/host_process.go b/test/e2e/windows/host_process.go index 156b5d821b3..d9562ec5619 100644 --- a/test/e2e/windows/host_process.go +++ b/test/e2e/windows/host_process.go @@ -85,7 +85,7 @@ var ( User_NTAuthoritySystem = "NT AUTHORITY\\SYSTEM" ) -var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersion:1.22] HostProcess containers", func() { +var _ = sigDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersion:1.22] HostProcess containers", skipUnlessWindows(func() { ginkgo.BeforeEach(func() { e2eskipper.SkipUnlessNodeOSDistroIs("windows") }) @@ -799,7 +799,7 @@ var _ = SIGDescribe("[Feature:WindowsHostProcessContainers] [MinimumKubeletVersi gomega.Expect(strings.ToLower(logs)).ShouldNot(gomega.ContainSubstring("nt authority"), "Container runs 'whoami' and logs should not contain 'nt authority'") }) -}) +})) func makeTestPodWithVolumeMounts(name string) *v1.Pod { hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate diff --git a/test/e2e/windows/hybrid_network.go b/test/e2e/windows/hybrid_network.go index 20a3ef6d32a..e2d05a3ec3c 100644 --- a/test/e2e/windows/hybrid_network.go +++ b/test/e2e/windows/hybrid_network.go @@ -44,7 +44,7 @@ var ( linuxBusyBoxImage = imageutils.GetE2EImage(imageutils.Nginx) ) -var _ = SIGDescribe("Hybrid cluster network", func() { +var _ = sigDescribe("Hybrid cluster network", skipUnlessWindows(func() { f := framework.NewDefaultFramework("hybrid-network") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -99,7 +99,7 @@ var _ = SIGDescribe("Hybrid cluster network", func() { }) }) -}) +})) var ( warmUpDuration = "30s" diff --git a/test/e2e/windows/hyperv.go b/test/e2e/windows/hyperv.go index fe188d80b30..edeccc5feac 100644 --- a/test/e2e/windows/hyperv.go +++ b/test/e2e/windows/hyperv.go @@ -35,7 +35,7 @@ var ( WindowsHyperVContainerRuntimeClass = "runhcs-wcow-hypervisor" ) -var _ = SIGDescribe("[Feature:WindowsHyperVContainers] HyperV containers", func() { +var _ = sigDescribe("[Feature:WindowsHyperVContainers] HyperV containers", skipUnlessWindows(func() { ginkgo.BeforeEach(func() { e2eskipper.SkipUnlessNodeOSDistroIs("windows") }) @@ -143,4 +143,4 @@ var _ = SIGDescribe("[Feature:WindowsHyperVContainers] HyperV containers", func( gomega.Expect(p.Status.Phase).To(gomega.Equal(v1.PodSucceeded), "pod should have succeeded") }) -}) +})) diff --git a/test/e2e/windows/kubelet_stats.go b/test/e2e/windows/kubelet_stats.go index 7d5826e9eb0..8c93c177fb5 100644 --- a/test/e2e/windows/kubelet_stats.go +++ b/test/e2e/windows/kubelet_stats.go @@ -37,7 +37,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() { +var _ = sigDescribe("[Feature:Windows] Kubelet-Stats [Serial]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("kubelet-stats-test-windows-serial") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -113,8 +113,9 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() { }) }) }) -}) -var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() { +})) + +var _ = sigDescribe("[Feature:Windows] Kubelet-Stats", skipUnlessWindows(func() { f := framework.NewDefaultFramework("kubelet-stats-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -204,7 +205,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() { }) }) }) -}) +})) // findWindowsNode finds a Windows node that is Ready and Schedulable func findWindowsNode(ctx context.Context, f *framework.Framework) (v1.Node, error) { diff --git a/test/e2e/windows/memory_limits.go b/test/e2e/windows/memory_limits.go index da96baad3fe..d108e2a495b 100644 --- a/test/e2e/windows/memory_limits.go +++ b/test/e2e/windows/memory_limits.go @@ -39,7 +39,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("[Feature:Windows] Memory Limits [Serial] [Slow]", func() { +var _ = sigDescribe("[Feature:Windows] Memory Limits [Serial] [Slow]", skipUnlessWindows(func() { f := framework.NewDefaultFramework("memory-limit-test-windows") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -60,8 +60,7 @@ var _ = SIGDescribe("[Feature:Windows] Memory Limits [Serial] [Slow]", func() { overrideAllocatableMemoryTest(ctx, f, framework.TestContext.CloudConfig.NumNodes) }) }) - -}) +})) type nodeMemory struct { // capacity diff --git a/test/e2e/windows/reboot_node.go b/test/e2e/windows/reboot_node.go index 51226e377de..a1b7790f60f 100644 --- a/test/e2e/windows/reboot_node.go +++ b/test/e2e/windows/reboot_node.go @@ -34,7 +34,7 @@ import ( admissionapi "k8s.io/pod-security-admission/api" ) -var _ = SIGDescribe("[Feature:Windows] [Excluded:WindowsDocker] [MinimumKubeletVersion:1.22] RebootHost containers [Serial] [Disruptive] [Slow]", func() { +var _ = sigDescribe("[Feature:Windows] [Excluded:WindowsDocker] [MinimumKubeletVersion:1.22] RebootHost containers [Serial] [Disruptive] [Slow]", skipUnlessWindows(func() { ginkgo.BeforeEach(func() { e2eskipper.SkipUnlessNodeOSDistroIs("windows") }) @@ -254,4 +254,4 @@ var _ = SIGDescribe("[Feature:Windows] [Excluded:WindowsDocker] [MinimumKubeletV framework.ExpectNoError(err, "Error retrieving pod") gomega.Expect(p.Status.Phase).To(gomega.Equal(v1.PodSucceeded)) }) -}) +})) diff --git a/test/e2e/windows/security_context.go b/test/e2e/windows/security_context.go index 2278b80e2f8..f72dd48ef3e 100644 --- a/test/e2e/windows/security_context.go +++ b/test/e2e/windows/security_context.go @@ -40,7 +40,7 @@ import ( const runAsUserNameContainerName = "run-as-username-container" -var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() { +var _ = sigDescribe("[Feature:Windows] SecurityContext", skipUnlessWindows(func() { f := framework.NewDefaultFramework("windows-run-as-username") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -190,7 +190,7 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext", func() { expectedEventError := "container's runAsUserName (CONTAINERADMINISTRATOR) which will be regarded as root identity and will break non-root policy" gomega.Expect(event.Message).Should(gomega.ContainSubstring(expectedEventError), "Event error should indicate non-root policy caused container to not start") }) -}) +})) func runAsUserNamePod(username *string) *v1.Pod { podName := "run-as-username-" + string(uuid.NewUUID()) diff --git a/test/e2e/windows/service.go b/test/e2e/windows/service.go index 657c2bc516e..e7c431e2598 100644 --- a/test/e2e/windows/service.go +++ b/test/e2e/windows/service.go @@ -36,7 +36,7 @@ import ( "github.com/onsi/gomega" ) -var _ = SIGDescribe("Services", func() { +var _ = sigDescribe("Services", skipUnlessWindows(func() { f := framework.NewDefaultFramework("services") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged @@ -85,5 +85,4 @@ var _ = SIGDescribe("Services", func() { assertConsistentConnectivity(ctx, f, testPod.ObjectMeta.Name, windowsOS, windowsCheck(fmt.Sprintf("http://%s", net.JoinHostPort(nodeIP, strconv.Itoa(nodePort))))) }) - -}) +})) diff --git a/test/e2e/windows/volumes.go b/test/e2e/windows/volumes.go index 1d1c8fe81d7..31fb6918cb4 100644 --- a/test/e2e/windows/volumes.go +++ b/test/e2e/windows/volumes.go @@ -44,7 +44,7 @@ var ( image = imageutils.GetE2EImage(imageutils.Pause) ) -var _ = SIGDescribe("[Feature:Windows] Windows volume mounts", func() { +var _ = sigDescribe("[Feature:Windows] Windows volume mounts", skipUnlessWindows(func() { f := framework.NewDefaultFramework("windows-volumes") f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged var ( @@ -86,8 +86,7 @@ var _ = SIGDescribe("[Feature:Windows] Windows volume mounts", func() { }) }) - -}) +})) func doReadOnlyTest(ctx context.Context, f *framework.Framework, source v1.VolumeSource, volumePath string) { var ( diff --git a/test/e2e_node/framework.go b/test/e2e_node/framework.go index f2a7c34651d..ad2b27a6110 100644 --- a/test/e2e_node/framework.go +++ b/test/e2e_node/framework.go @@ -16,9 +16,7 @@ limitations under the License. package e2enode -import "github.com/onsi/ginkgo/v2" +import "k8s.io/kubernetes/test/e2e/framework" // SIGDescribe annotates the test with the SIG label. -func SIGDescribe(text string, body func()) bool { - return ginkgo.Describe("[sig-node] "+text, body) -} +var SIGDescribe = framework.SIGDescribe("node")