diff --git a/test/e2e/common/networking.go b/test/e2e/common/networking.go index cbfc66a87f7..e48a646aca2 100644 --- a/test/e2e/common/networking.go +++ b/test/e2e/common/networking.go @@ -38,7 +38,7 @@ var _ = Describe("[sig-network] Networking", func() { This test is marked LinuxOnly since HostNetwork is not supported on other platforms like Windows. */ framework.ConformanceIt("should function for intra-pod communication: http [LinuxOnly] [NodeConformance]", func() { - config := framework.NewCoreNetworkingTestConfig(f) + config := framework.NewCoreNetworkingTestConfig(f, true) for _, endpointPod := range config.EndpointPods { config.DialFromTestContainer("http", endpointPod.Status.PodIP, framework.EndpointHttpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) } @@ -52,7 +52,7 @@ var _ = Describe("[sig-network] Networking", func() { This test is marked LinuxOnly since HostNetwork is not supported on other platforms like Windows. */ framework.ConformanceIt("should function for intra-pod communication: udp [LinuxOnly] [NodeConformance]", func() { - config := framework.NewCoreNetworkingTestConfig(f) + config := framework.NewCoreNetworkingTestConfig(f, true) for _, endpointPod := range config.EndpointPods { config.DialFromTestContainer("udp", endpointPod.Status.PodIP, framework.EndpointUdpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) } @@ -66,7 +66,7 @@ var _ = Describe("[sig-network] Networking", func() { This test is marked LinuxOnly since HostNetwork is not supported on other platforms like Windows. */ framework.ConformanceIt("should function for node-pod communication: http [LinuxOnly] [NodeConformance]", func() { - config := framework.NewCoreNetworkingTestConfig(f) + config := framework.NewCoreNetworkingTestConfig(f, true) for _, endpointPod := range config.EndpointPods { config.DialFromNode("http", endpointPod.Status.PodIP, framework.EndpointHttpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) } @@ -80,7 +80,7 @@ var _ = Describe("[sig-network] Networking", func() { This test is marked LinuxOnly since HostNetwork is not supported on other platforms like Windows. */ framework.ConformanceIt("should function for node-pod communication: udp [LinuxOnly] [NodeConformance]", func() { - config := framework.NewCoreNetworkingTestConfig(f) + config := framework.NewCoreNetworkingTestConfig(f, true) for _, endpointPod := range config.EndpointPods { config.DialFromNode("udp", endpointPod.Status.PodIP, framework.EndpointUdpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) } diff --git a/test/e2e/framework/networking_utils.go b/test/e2e/framework/networking_utils.go index 01de115692b..d42a78bb9bd 100644 --- a/test/e2e/framework/networking_utils.go +++ b/test/e2e/framework/networking_utils.go @@ -69,15 +69,15 @@ var NetexecImageName = imageutils.GetE2EImage(imageutils.Netexec) // NewNetworkingTestConfig creates and sets up a new test config helper. func NewNetworkingTestConfig(f *Framework) *NetworkingTestConfig { - config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name} + config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name, HostNetwork: true} By(fmt.Sprintf("Performing setup for networking test in namespace %v", config.Namespace)) config.setup(getServiceSelector()) return config } // NewNetworkingTestNodeE2EConfig creates and sets up a new test config helper for Node E2E. -func NewCoreNetworkingTestConfig(f *Framework) *NetworkingTestConfig { - config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name} +func NewCoreNetworkingTestConfig(f *Framework, hostNetwork bool) *NetworkingTestConfig { + config := &NetworkingTestConfig{f: f, Namespace: f.Namespace.Name, HostNetwork: hostNetwork} By(fmt.Sprintf("Performing setup for networking test in namespace %v", config.Namespace)) config.setupCore(getServiceSelector()) return config @@ -98,9 +98,10 @@ type NetworkingTestConfig struct { // TestContaienrPod is a test pod running the netexec image. It is capable // of executing tcp/udp requests against ip:port. TestContainerPod *v1.Pod - // HostTestContainerPod is a pod running with hostNetworking=true, and the - // hostexec image. + // HostTestContainerPod is a pod running using the hostexec image. HostTestContainerPod *v1.Pod + // if the HostTestContainerPod is running with HostNetwork=true. + HostNetwork bool // EndpointPods are the pods belonging to the Service created by this // test config. Each invocation of `setup` creates a service with // 1 pod per node running the netexecImage. @@ -513,7 +514,7 @@ func (config *NetworkingTestConfig) DeleteNodePortService() { func (config *NetworkingTestConfig) createTestPods() { testContainerPod := config.createTestPodSpec() - hostTestContainerPod := NewHostExecPodSpec(config.Namespace, hostTestPodName) + hostTestContainerPod := NewExecPodSpec(config.Namespace, hostTestPodName, config.HostNetwork) config.createPod(testContainerPod) config.createPod(hostTestContainerPod) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 7256ab61eb3..789f5b2ae37 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -3382,8 +3382,8 @@ func NodeAddresses(nodelist *v1.NodeList, addrType v1.NodeAddressType) []string return hosts } -// NewHostExecPodSpec returns the pod spec of hostexec pod -func NewHostExecPodSpec(ns, name string) *v1.Pod { +// NewExecPodSpec returns the pod spec of hostexec pod +func NewExecPodSpec(ns, name string, hostNetwork bool) *v1.Pod { immediate := int64(0) pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ @@ -3398,7 +3398,7 @@ func NewHostExecPodSpec(ns, name string) *v1.Pod { ImagePullPolicy: v1.PullIfNotPresent, }, }, - HostNetwork: true, + HostNetwork: hostNetwork, SecurityContext: &v1.PodSecurityContext{}, TerminationGracePeriodSeconds: &immediate, }, @@ -3441,7 +3441,7 @@ func RunHostCmdWithRetries(ns, name, cmd string, interval, timeout time.Duration // LaunchHostExecPod launches a hostexec pod in the given namespace and waits // until it's Running func LaunchHostExecPod(client clientset.Interface, ns, name string) *v1.Pod { - hostExecPod := NewHostExecPodSpec(ns, name) + hostExecPod := NewExecPodSpec(ns, name, true) pod, err := client.CoreV1().Pods(ns).Create(hostExecPod) ExpectNoError(err) err = WaitForPodRunningInNamespace(client, pod) diff --git a/test/e2e/storage/persistent_volumes-local.go b/test/e2e/storage/persistent_volumes-local.go index 047ca401686..6093c71a0dd 100644 --- a/test/e2e/storage/persistent_volumes-local.go +++ b/test/e2e/storage/persistent_volumes-local.go @@ -824,7 +824,7 @@ func setupLocalVolumeDirectory(config *localTestConfig, node *v1.Node) *localTes // launchNodeExecPodForLocalPV launches a hostexec pod for local PV and waits // until it's Running. func launchNodeExecPodForLocalPV(client clientset.Interface, ns, node string) *v1.Pod { - hostExecPod := framework.NewHostExecPodSpec(ns, fmt.Sprintf("hostexec-%s", node)) + hostExecPod := framework.NewExecPodSpec(ns, fmt.Sprintf("hostexec-%s", node), true) hostExecPod.Spec.NodeName = node hostExecPod.Spec.Volumes = []v1.Volume{ { diff --git a/test/e2e/storage/utils/host_exec.go b/test/e2e/storage/utils/host_exec.go index 4fd5b4f23f3..48c1e71f900 100644 --- a/test/e2e/storage/utils/host_exec.go +++ b/test/e2e/storage/utils/host_exec.go @@ -50,7 +50,7 @@ func (h *hostExecutor) launchNodeExecPod(node string) *v1.Pod { f := h.Framework cs := f.ClientSet ns := f.Namespace - hostExecPod := framework.NewHostExecPodSpec(ns.Name, fmt.Sprintf("hostexec-%s", node)) + hostExecPod := framework.NewExecPodSpec(ns.Name, fmt.Sprintf("hostexec-%s", node), true) hostExecPod.Spec.NodeName = node hostExecPod.Spec.Volumes = []v1.Volume{ { diff --git a/test/e2e/windows/BUILD b/test/e2e/windows/BUILD index 98bb0a34cdf..0668d02d6a1 100644 --- a/test/e2e/windows/BUILD +++ b/test/e2e/windows/BUILD @@ -7,6 +7,7 @@ go_library( srcs = [ "density.go", "framework.go", + "networking.go", ], importpath = "k8s.io/kubernetes/test/e2e/windows", visibility = ["//visibility:public"], @@ -15,6 +16,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library", "//staging/src/k8s.io/client-go/tools/cache:go_default_library", diff --git a/test/e2e/windows/networking.go b/test/e2e/windows/networking.go new file mode 100644 index 00000000000..ba7e0074787 --- /dev/null +++ b/test/e2e/windows/networking.go @@ -0,0 +1,94 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package windows + +import ( + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/kubernetes/test/e2e/framework" + + . "github.com/onsi/ginkgo" +) + +// NOTE(claudiub): Spawning Pods With HostNetwork enabled is not currently supported by Windows Kubelet. +// TODO(claudiub): Remove this test suite once this PR merges: +// https://github.com/kubernetes/kubernetes/pull/69525 +var _ = Describe("[sig-network] [sig-windows] Networking", func() { + f := framework.NewDefaultFramework("pod-network-test") + + BeforeEach(func() { + // NOTE(claudiub): These tests are Windows specific. + framework.SkipUnlessNodeOSDistroIs("windows") + }) + + Describe("Granular Checks: Pods", func() { + + // Try to hit all endpoints through a test container, retry 5 times, + // expect exactly one unique hostname. Each of these endpoints reports + // its own hostname. + /* + Release : v1.14 + Testname: Networking, intra pod http + Description: Create a hostexec pod that is capable of curl to netcat commands. Create a test Pod that will act as a webserver front end exposing ports 8080 for tcp and 8081 for udp. The netserver service proxies are created on specified number of nodes. + The kubectl exec on the webserver container MUST reach a http port on the each of service proxy endpoints in the cluster and the request MUST be successful. Container will execute curl command to reach the service port within specified max retry limit and MUST result in reporting unique hostnames. + */ + It("should function for intra-pod communication: http", func() { + config := framework.NewCoreNetworkingTestConfig(f, false) + for _, endpointPod := range config.EndpointPods { + config.DialFromTestContainer("http", endpointPod.Status.PodIP, framework.EndpointHttpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) + } + }) + + /* + Release : v1.14 + Testname: Networking, intra pod udp + Description: Create a hostexec pod that is capable of curl to netcat commands. Create a test Pod that will act as a webserver front end exposing ports 8080 for tcp and 8081 for udp. The netserver service proxies are created on specified number of nodes. + The kubectl exec on the webserver container MUST reach a udp port on the each of service proxy endpoints in the cluster and the request MUST be successful. Container will execute curl command to reach the service port within specified max retry limit and MUST result in reporting unique hostnames. + */ + It("should function for intra-pod communication: udp", func() { + config := framework.NewCoreNetworkingTestConfig(f, false) + for _, endpointPod := range config.EndpointPods { + config.DialFromTestContainer("udp", endpointPod.Status.PodIP, framework.EndpointUdpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) + } + }) + + /* + Release : v1.14 + Testname: Networking, intra pod http, from node + Description: Create a hostexec pod that is capable of curl to netcat commands. Create a test Pod that will act as a webserver front end exposing ports 8080 for tcp and 8081 for udp. The netserver service proxies are created on specified number of nodes. + The kubectl exec on the webserver container MUST reach a http port on the each of service proxy endpoints in the cluster using a http post(protocol=tcp) and the request MUST be successful. Container will execute curl command to reach the service port within specified max retry limit and MUST result in reporting unique hostnames. + */ + It("should function for node-pod communication: http", func() { + config := framework.NewCoreNetworkingTestConfig(f, false) + for _, endpointPod := range config.EndpointPods { + config.DialFromNode("http", endpointPod.Status.PodIP, framework.EndpointHttpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) + } + }) + + /* + Release : v1.14 + Testname: Networking, intra pod http, from node + Description: Create a hostexec pod that is capable of curl to netcat commands. Create a test Pod that will act as a webserver front end exposing ports 8080 for tcp and 8081 for udp. The netserver service proxies are created on specified number of nodes. + The kubectl exec on the webserver container MUST reach a http port on the each of service proxy endpoints in the cluster using a http post(protocol=udp) and the request MUST be successful. Container will execute curl command to reach the service port within specified max retry limit and MUST result in reporting unique hostnames. + */ + It("should function for node-pod communication: udp", func() { + config := framework.NewCoreNetworkingTestConfig(f, false) + for _, endpointPod := range config.EndpointPods { + config.DialFromNode("udp", endpointPod.Status.PodIP, framework.EndpointUdpPort, config.MaxTries, 0, sets.NewString(endpointPod.Name)) + } + }) + }) +})