Skip to content

Commit

Permalink
Merge pull request #81291 from danwinship/service-test-cleanup-1
Browse files Browse the repository at this point in the history
Inline/simplify two used-only-once service test helper functions
  • Loading branch information
k8s-ci-robot authored Aug 13, 2019
2 parents feb6da7 + 6a42e10 commit 61af419
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 90 deletions.
28 changes: 0 additions & 28 deletions test/e2e/framework/service/jig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 0 additions & 57 deletions test/e2e/framework/service/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion test/e2e/network/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,21 @@ 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)
framework.ExpectNoError(err, "failed to delete pod: %s on node", serverPodName)
}()

// 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")
Expand Down

0 comments on commit 61af419

Please sign in to comment.