Skip to content

Commit 766d79b

Browse files
committed
Make TestContext.IPFamily global for parallel testing
it turns out that the framework.TestContext.IPFamily variable is not available for the DNS tests if they don't run in the initial Ginkgo node when running in parallel. We add a function to the framework to allow us to run command only once per each Ginkgo node parallel execution. It also adds a method to detect if the cluster is IPv6. The use of the framework.TestContext.IPFamily variable guarantees consistency all over the testing because this variable is only assigned at the beginning of the testing.
1 parent 28e8002 commit 766d79b

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

test/e2e/e2e.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
5353
return nil
5454
}, func(data []byte) {
5555
// Run on all Ginkgo nodes
56+
framework.SetupSuitePerGinkgoNode()
5657
})
5758

5859
var _ = ginkgo.SynchronizedAfterSuite(func() {

test/e2e/framework/log/logger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestFailureOutput(t *testing.T) {
8484
output: "INFO: before\nFAIL: hard-coded error\nUnexpected error:\n <*errors.errorString>: {\n s: \"an error with a long, useless description\",\n }\n an error with a long, useless description\noccurred\nINFO: after\nFAIL: true is never false either\nExpected\n <bool>: true\nto equal\n <bool>: false\n",
8585
failure: "hard-coded error\nUnexpected error:\n <*errors.errorString>: {\n s: \"an error with a long, useless description\",\n }\n an error with a long, useless description\noccurred",
8686
// TODO: should start with k8s.io/kubernetes/test/e2e/framework/log_test.glob..func1.4()
87-
stack: "\tutil.go:1362\nk8s.io/kubernetes/test/e2e/framework.ExpectNoError()\n\tutil.go:1356\nk8s.io/kubernetes/test/e2e/framework/log_test.glob..func1.4()\n\tlogger_test.go:49\nk8s.io/kubernetes/vendor/github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync()\n\tlogger_test.go:65\n",
87+
stack: "\tutil.go:1369\nk8s.io/kubernetes/test/e2e/framework.ExpectNoError()\n\tutil.go:1363\nk8s.io/kubernetes/test/e2e/framework/log_test.glob..func1.4()\n\tlogger_test.go:49\nk8s.io/kubernetes/vendor/github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync()\n\tlogger_test.go:65\n",
8888
},
8989
testResult{
9090
name: "[Top Level] log fails",

test/e2e/framework/suites.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,30 @@ func SetupSuite() {
116116
e2elog.Logf("kube-apiserver version: %s", serverVersion.GitVersion)
117117
}
118118

119+
if TestContext.NodeKiller.Enabled {
120+
nodeKiller := NewNodeKiller(TestContext.NodeKiller, c, TestContext.Provider)
121+
go nodeKiller.Run(TestContext.NodeKiller.NodeKillerStopCh)
122+
}
123+
}
124+
125+
// SetupSuitePerGinkgoNode is the boilerplate that can be used to setup ginkgo test suites, on the SynchronizedBeforeSuite step.
126+
// There are certain operations we only want to run once per overall test invocation on each Ginkgo node
127+
// such as making some global variables accessible to all parallel executions
128+
// Because of the way Ginkgo runs tests in parallel, we must use SynchronizedBeforeSuite
129+
// Ref: https://onsi.github.io/ginkgo/#parallel-specs
130+
func SetupSuitePerGinkgoNode() {
119131
// Obtain the default IP family of the cluster
120132
// Some e2e test are designed to work on IPv4 only, this global variable
121133
// allows to adapt those tests to work on both IPv4 and IPv6
122-
// TODO(dual-stack): dual stack clusters should pass full e2e testing at least with the primary IP family
134+
// TODO: dual-stack
123135
// the dual stack clusters can be ipv4-ipv6 or ipv6-ipv4, order matters,
124136
// and services use the primary IP family by default
125-
// If we´ll need to provide additional context for dual-stack, we can detect it
126-
// because pods have two addresses (one per family)
137+
c, err := LoadClientset()
138+
if err != nil {
139+
klog.Fatal("Error loading client: ", err)
140+
}
127141
TestContext.IPFamily = getDefaultClusterIPFamily(c)
128142
e2elog.Logf("Cluster IP family: %s", TestContext.IPFamily)
129-
130-
if TestContext.NodeKiller.Enabled {
131-
nodeKiller := NewNodeKiller(TestContext.NodeKiller, c, TestContext.Provider)
132-
go nodeKiller.Run(TestContext.NodeKiller.NodeKillerStopCh)
133-
}
134143
}
135144

136145
// CleanupSuite is the boilerplate that can be used after tests on ginkgo were run, on the SynchronizedAfterSuite step.

test/e2e/framework/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ func runKubernetesServiceTestContainer(c clientset.Interface, ns string) {
415415
// getDefaultClusterIPFamily obtains the default IP family of the cluster
416416
// using the Cluster IP address of the kubernetes service created in the default namespace
417417
// This unequivocally identifies the default IP family because services are single family
418+
// TODO: dual-stack may support multiple families per service
419+
// but we can detect if a cluster is dual stack because pods have two addresses (one per family)
418420
func getDefaultClusterIPFamily(c clientset.Interface) string {
419421
// Get the ClusterIP of the kubernetes service created in the default namespace
420422
svc, err := c.CoreV1().Services(metav1.NamespaceDefault).Get("kubernetes", metav1.GetOptions{})
@@ -428,6 +430,11 @@ func getDefaultClusterIPFamily(c clientset.Interface) string {
428430
return "ipv4"
429431
}
430432

433+
// ClusterIsIPv6 returns true if the cluster is IPv6
434+
func ClusterIsIPv6() bool {
435+
return TestContext.IPFamily == "ipv6"
436+
}
437+
431438
// ProviderIs returns true if the provider is included is the providers. Otherwise false.
432439
func ProviderIs(providers ...string) bool {
433440
for _, provider := range providers {

0 commit comments

Comments
 (0)