Merge pull request #84258 from oomichi/move-TranslateIPv4ToIPv6

Move TranslateIPv4ToIPv6() to e2e scheduling test
This commit is contained in:
Kubernetes Prow Robot 2019-10-24 16:56:31 -07:00 committed by GitHub
commit 39a8417510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -40,7 +40,6 @@ 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 (
@ -76,16 +75,6 @@ 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 != "" {
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}

View File

@ -55,6 +55,7 @@ go_library(
"//vendor/github.com/onsi/gomega:go_default_library", "//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/google.golang.org/api/compute/v1:go_default_library", "//vendor/google.golang.org/api/compute/v1:go_default_library",
"//vendor/k8s.io/utils/net:go_default_library",
], ],
) )

View File

@ -34,6 +34,7 @@ import (
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
testutils "k8s.io/kubernetes/test/utils" testutils "k8s.io/kubernetes/test/utils"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
k8utilnet "k8s.io/utils/net"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
@ -810,7 +811,7 @@ func CreateNodeSelectorPods(f *framework.Framework, id string, replicas int, nod
// 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) hostIP = translateIPv4ToIPv6(hostIP)
createPausePod(f, pausePodConfig{ createPausePod(f, pausePodConfig{
Name: podName, Name: podName,
Ports: []v1.ContainerPort{ Ports: []v1.ContainerPort{
@ -829,3 +830,13 @@ func createHostPortPodOnNode(f *framework.Framework, podName, ns, hostIP string,
framework.ExpectNoError(err) framework.ExpectNoError(err)
} }
} }
// 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 framework.TestContext.IPFamily == "ipv6" && !k8utilnet.IsIPv6String(ip) && ip != "" {
ip = "0::ffff:" + ip
}
return ip
}