mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
e2e: Autodetect the IP family of the cluster
This commit is contained in:
parent
c2a4369ba4
commit
daff471766
@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user