mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Merge pull request #80398 from aojea/ipfamily
Add ip family autodetection to the testing framework
This commit is contained in:
commit
cc0137cdc6
@ -83,6 +83,7 @@ go_library(
|
|||||||
"//vendor/github.com/onsi/ginkgo/reporters:go_default_library",
|
"//vendor/github.com/onsi/ginkgo/reporters:go_default_library",
|
||||||
"//vendor/github.com/onsi/gomega:go_default_library",
|
"//vendor/github.com/onsi/gomega:go_default_library",
|
||||||
"//vendor/k8s.io/klog: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"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
"k8s.io/kubernetes/test/e2e/manifest"
|
"k8s.io/kubernetes/test/e2e/manifest"
|
||||||
testutils "k8s.io/kubernetes/test/utils"
|
testutils "k8s.io/kubernetes/test/utils"
|
||||||
|
utilnet "k8s.io/utils/net"
|
||||||
|
|
||||||
// ensure auth plugins are loaded
|
// ensure auth plugins are loaded
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
@ -143,6 +144,17 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
|
|||||||
e2elog.Logf("kube-apiserver version: %s", serverVersion.GitVersion)
|
e2elog.Logf("kube-apiserver version: %s", serverVersion.GitVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtain the default IP family of the cluster
|
||||||
|
// Some e2e test are designed to work on IPv4 only, this global variable
|
||||||
|
// allows to adapt those tests to work on both IPv4 and IPv6
|
||||||
|
// TODO(dual-stack): dual stack clusters should pass full e2e testing at least with the primary IP family
|
||||||
|
// the dual stack clusters can be ipv4-ipv6 or ipv6-ipv4, order matters,
|
||||||
|
// and services use the primary IP family by default
|
||||||
|
// If we´ll need to provide additional context for dual-stack, we can detect it
|
||||||
|
// because pods have two addresses (one per family)
|
||||||
|
framework.TestContext.IPFamily = getDefaultClusterIPFamily(c)
|
||||||
|
e2elog.Logf("Cluster IP family: %s", framework.TestContext.IPFamily)
|
||||||
|
|
||||||
// Reference common test to make the import valid.
|
// Reference common test to make the import valid.
|
||||||
commontest.CurrentSuite = commontest.E2E
|
commontest.CurrentSuite = commontest.E2E
|
||||||
|
|
||||||
@ -276,3 +288,19 @@ func runKubernetesServiceTestContainer(c clientset.Interface, ns string) {
|
|||||||
e2elog.Logf("Output of clusterapi-tester:\n%v", logs)
|
e2elog.Logf("Output of clusterapi-tester:\n%v", logs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getDefaultClusterIPFamily obtains the default IP family of the cluster
|
||||||
|
// using the Cluster IP address of the kubernetes service created in the default namespace
|
||||||
|
// This unequivocally identifies the default IP family because services are single family
|
||||||
|
func getDefaultClusterIPFamily(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 service ClusterIP: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if utilnet.IsIPv6String(svc.Spec.ClusterIP) {
|
||||||
|
return "ipv6"
|
||||||
|
}
|
||||||
|
return "ipv4"
|
||||||
|
}
|
||||||
|
@ -113,6 +113,7 @@ go_library(
|
|||||||
"//vendor/golang.org/x/net/websocket:go_default_library",
|
"//vendor/golang.org/x/net/websocket:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
"//vendor/k8s.io/utils/exec:go_default_library",
|
"//vendor/k8s.io/utils/exec:go_default_library",
|
||||||
|
"//vendor/k8s.io/utils/net:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ import (
|
|||||||
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
|
||||||
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
|
k8utilnet "k8s.io/utils/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -77,6 +78,16 @@ const (
|
|||||||
// NetexecImageName is the image name for agnhost.
|
// NetexecImageName is the image name for agnhost.
|
||||||
var NetexecImageName = imageutils.GetE2EImage(imageutils.Agnhost)
|
var NetexecImageName = imageutils.GetE2EImage(imageutils.Agnhost)
|
||||||
|
|
||||||
|
// TranslateIPv4ToIPv6 maps an IPv4 address into a valid IPv6 address
|
||||||
|
// adding the well known prefix "0::ffff:" https://tools.ietf.org/html/rfc2765
|
||||||
|
// if the ip is IPv4 and the cluster IPFamily is IPv6, otherwise returns the same ip
|
||||||
|
func TranslateIPv4ToIPv6(ip string) string {
|
||||||
|
if TestContext.IPFamily == "ipv6" && !k8utilnet.IsIPv6String(ip) {
|
||||||
|
ip = "0::ffff:" + ip
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
// NewNetworkingTestConfig creates and sets up a new test config helper.
|
// NewNetworkingTestConfig creates and sets up a new test config helper.
|
||||||
func NewNetworkingTestConfig(f *Framework) *NetworkingTestConfig {
|
func NewNetworkingTestConfig(f *Framework) *NetworkingTestConfig {
|
||||||
config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name, HostNetwork: true}
|
config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name, HostNetwork: true}
|
||||||
|
@ -164,6 +164,9 @@ type TestContextType struct {
|
|||||||
|
|
||||||
// The configuration of NodeKiller.
|
// The configuration of NodeKiller.
|
||||||
NodeKiller NodeKillerConfig
|
NodeKiller NodeKillerConfig
|
||||||
|
|
||||||
|
// The Default IP Family of the cluster ("ipv4" or "ipv6")
|
||||||
|
IPFamily string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeKillerConfig describes configuration of NodeKiller -- a utility to
|
// NodeKillerConfig describes configuration of NodeKiller -- a utility to
|
||||||
|
@ -825,6 +825,7 @@ func CreateHostPortPods(f *framework.Framework, id string, replicas int, expectR
|
|||||||
|
|
||||||
// create pod which using hostport on the specified node according to the nodeSelector
|
// create pod which using hostport on the specified node according to the nodeSelector
|
||||||
func createHostPortPodOnNode(f *framework.Framework, podName, ns, hostIP string, port int32, protocol v1.Protocol, nodeSelector map[string]string, expectScheduled bool) {
|
func createHostPortPodOnNode(f *framework.Framework, podName, ns, hostIP string, port int32, protocol v1.Protocol, nodeSelector map[string]string, expectScheduled bool) {
|
||||||
|
hostIP = framework.TranslateIPv4ToIPv6(hostIP)
|
||||||
createPausePod(f, pausePodConfig{
|
createPausePod(f, pausePodConfig{
|
||||||
Name: podName,
|
Name: podName,
|
||||||
Ports: []v1.ContainerPort{
|
Ports: []v1.ContainerPort{
|
||||||
|
Loading…
Reference in New Issue
Block a user