diff --git a/test/e2e/framework/service/jig.go b/test/e2e/framework/service/jig.go index 6e895afe8165d..fac30235175b7 100644 --- a/test/e2e/framework/service/jig.go +++ b/test/e2e/framework/service/jig.go @@ -879,34 +879,6 @@ func (j *TestJig) CheckServiceReachability(namespace string, svc *v1.Service, po } } -// LaunchNetexecPodOnNode launches a netexec pod on the given node. -func (j *TestJig) LaunchNetexecPodOnNode(f *framework.Framework, nodeName, podName string, httpPort, udpPort int32, hostNetwork bool) { - e2elog.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, f.Namespace.Name) - pod := newNetexecPodSpec(podName, httpPort, udpPort, hostNetwork) - pod.Spec.NodeName = nodeName - pod.ObjectMeta.Labels = j.Labels - podClient := f.ClientSet.CoreV1().Pods(f.Namespace.Name) - _, err := podClient.Create(pod) - framework.ExpectNoError(err) - framework.ExpectNoError(f.WaitForPodRunning(podName)) - e2elog.Logf("Netexec pod %q in namespace %q running", pod.Name, f.Namespace.Name) -} - -// LaunchEchoserverPodOnNode launches a pod serving http on port 8080 to act -// as the target for source IP preservation test. The client's source ip would -// be echoed back by the web server. -func (j *TestJig) LaunchEchoserverPodOnNode(f *framework.Framework, nodeName, podName string) { - e2elog.Logf("Creating echo server pod %q in namespace %q", podName, f.Namespace.Name) - pod := newEchoServerPodSpec(podName) - pod.Spec.NodeName = nodeName - pod.ObjectMeta.Labels = j.Labels - podClient := f.ClientSet.CoreV1().Pods(f.Namespace.Name) - _, err := podClient.Create(pod) - framework.ExpectNoError(err) - framework.ExpectNoError(f.WaitForPodRunning(podName)) - e2elog.Logf("Echo server pod %q in namespace %q running", pod.Name, f.Namespace.Name) -} - // TestReachableHTTP tests that the given host serves HTTP on the given port. func (j *TestJig) TestReachableHTTP(host string, port int, timeout time.Duration) { j.TestReachableHTTPWithRetriableErrorCodes(host, port, []int{}, timeout) diff --git a/test/e2e/framework/service/resource.go b/test/e2e/framework/service/resource.go index a46a65f0dc54a..cae76c39e5adf 100644 --- a/test/e2e/framework/service/resource.go +++ b/test/e2e/framework/service/resource.go @@ -27,7 +27,6 @@ import ( restclient "k8s.io/client-go/rest" "k8s.io/kubernetes/test/e2e/framework" e2elog "k8s.io/kubernetes/test/e2e/framework/log" - imageutils "k8s.io/kubernetes/test/utils/image" ) // GetServicesProxyRequest returns a request for a service proxy. @@ -110,62 +109,6 @@ func DescribeSvc(ns string) { e2elog.Logf(desc) } -// newNetexecPodSpec returns the pod spec of netexec pod -func newNetexecPodSpec(podName string, httpPort, udpPort int32, hostNetwork bool) *v1.Pod { - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: podName, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "netexec", - Image: framework.NetexecImageName, - Args: []string{ - "netexec", - fmt.Sprintf("--http-port=%d", httpPort), - fmt.Sprintf("--udp-port=%d", udpPort), - }, - Ports: []v1.ContainerPort{ - { - Name: "http", - ContainerPort: httpPort, - }, - { - Name: "udp", - ContainerPort: udpPort, - }, - }, - }, - }, - HostNetwork: hostNetwork, - }, - } - return pod -} - -// newEchoServerPodSpec returns the pod spec of echo server pod -func newEchoServerPodSpec(podName string) *v1.Pod { - port := 8080 - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: podName, - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{ - { - Name: "echoserver", - Image: imageutils.GetE2EImage(imageutils.Agnhost), - Args: []string{"netexec", fmt.Sprintf("--http-port=%d", port)}, - Ports: []v1.ContainerPort{{ContainerPort: int32(port)}}, - }, - }, - RestartPolicy: v1.RestartPolicyNever, - }, - } - return pod -} - // GetServiceLoadBalancerCreationTimeout returns a timeout value for creating a load balancer of a service. func GetServiceLoadBalancerCreationTimeout(cs clientset.Interface) time.Duration { if nodes := framework.GetReadySchedulableNodesOrDie(cs); len(nodes.Items) > LargeClusterMinNodesNumber { diff --git a/test/e2e/network/firewall.go b/test/e2e/network/firewall.go index f4c0934dc870c..da1fdf7cae3a3 100644 --- a/test/e2e/network/firewall.go +++ b/test/e2e/network/firewall.go @@ -135,7 +135,20 @@ var _ = SIGDescribe("Firewall rule", func() { ginkgo.By(fmt.Sprintf("Creating netexec pods on at most %v nodes", e2eservice.MaxNodesForEndpointsTests)) for i, nodeName := range nodesNames { podName := fmt.Sprintf("netexec%v", i) - jig.LaunchNetexecPodOnNode(f, nodeName, podName, firewallTestHTTPPort, firewallTestUDPPort, true) + + e2elog.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, ns) + pod := f.NewAgnhostPod(podName, + "netexec", + fmt.Sprintf("--http-port=%d", firewallTestHTTPPort), + fmt.Sprintf("--udp-port=%d", firewallTestUDPPort)) + pod.ObjectMeta.Labels = jig.Labels + pod.Spec.NodeName = nodeName + pod.Spec.HostNetwork = true + _, err := cs.CoreV1().Pods(ns).Create(pod) + framework.ExpectNoError(err) + framework.ExpectNoError(f.WaitForPodRunning(podName)) + e2elog.Logf("Netexec pod %q in namespace %q running", podName, ns) + defer func() { e2elog.Logf("Cleaning up the netexec pod: %v", podName) err = cs.CoreV1().Pods(ns).Delete(podName, nil) diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index 54a31620f67c6..e499d8fb6e526 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -300,9 +300,13 @@ var _ = SIGDescribe("Services", func() { framework.Skipf("The test requires at least two ready nodes on %s, but found %v", framework.TestContext.Provider, nodeCounts) } - ginkgo.By("Creating a webserver pod be part of the TCP service which echoes back source ip") - serverPodName := "echoserver-sourceip" - jig.LaunchEchoserverPodOnNode(f, "", serverPodName) + ginkgo.By("Creating a webserver pod to be part of the TCP service which echoes back source ip") + serverPodName := "echo-sourceip" + pod := f.NewAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort)) + pod.Labels = jig.Labels + _, err := cs.CoreV1().Pods(ns).Create(pod) + framework.ExpectNoError(err) + framework.ExpectNoError(f.WaitForPodRunning(pod.Name)) defer func() { e2elog.Logf("Cleaning up the echo server pod") err := cs.CoreV1().Pods(ns).Delete(serverPodName, nil) @@ -310,7 +314,7 @@ var _ = SIGDescribe("Services", func() { }() // Waiting for service to expose endpoint. - err := e2eendpoints.ValidateEndpointsPorts(cs, ns, serviceName, e2eendpoints.PortsByPodName{serverPodName: {servicePort}}) + err = e2eendpoints.ValidateEndpointsPorts(cs, ns, serviceName, e2eendpoints.PortsByPodName{serverPodName: {servicePort}}) framework.ExpectNoError(err, "failed to validate endpoints for service %s in namespace: %s", serviceName, ns) ginkgo.By("Creating pause pod deployment")