e2e: Autodetect the IP family of the cluster

This commit is contained in:
Antonio Ojea 2019-07-23 09:04:47 +02:00
parent c2a4369ba4
commit daff471766
No known key found for this signature in database
GPG Key ID: E4833AA228D4E824
3 changed files with 27 additions and 0 deletions

View File

@ -83,6 +83,7 @@ go_library(
"//vendor/github.com/onsi/ginkgo/reporters:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
"//vendor/k8s.io/utils/net:go_default_library",
],
)

View File

@ -43,6 +43,7 @@ import (
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
"k8s.io/kubernetes/test/e2e/manifest"
testutils "k8s.io/kubernetes/test/utils"
utilnet "k8s.io/utils/net"
// ensure auth plugins are loaded
_ "k8s.io/client-go/plugin/pkg/client/auth"
@ -143,6 +144,13 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
e2elog.Logf("kube-apiserver version: %s", serverVersion.GitVersion)
}
// Obtain the (primary if dual stack) ip family of the cluster
framework.TestContext.IPFamily = getClusterIPFamily(c)
e2elog.Logf("Cluster IP family: %s", framework.TestContext.IPFamily)
// TODO(dual-stack): dual-stack clusters use two pods addresses (one per family)
// the cluster can be ipv4-ipv6 or ipv6-ipv4, order matters
// Reference common test to make the import valid.
commontest.CurrentSuite = commontest.E2E
@ -276,3 +284,18 @@ func runKubernetesServiceTestContainer(c clientset.Interface, ns string) {
e2elog.Logf("Output of clusterapi-tester:\n%v", logs)
}
}
// getClusterIPFamily obtains the (primary) ip family of the cluster based
// on the Cluster IP address of the default kubernetes service
func getClusterIPFamily(c clientset.Interface) string {
// Get the ClusterIP of the kubernetes service created in the default namespace
svc, err := c.CoreV1().Services(metav1.NamespaceDefault).Get("kubernetes", metav1.GetOptions{})
if err != nil {
e2elog.Failf("Failed to get kubernetes endpoints: %v", err)
}
if utilnet.IsIPv6String(svc.Spec.ClusterIP) {
return "ipv6"
}
return "ipv4"
}

View File

@ -164,6 +164,9 @@ type TestContextType struct {
// The configuration of NodeKiller.
NodeKiller NodeKillerConfig
// The IP Family of the cluster
IPFamily string
}
// NodeKillerConfig describes configuration of NodeKiller -- a utility to