From e4542e2c675f0929ce8c9e5ffa2c1394e9538e31 Mon Sep 17 00:00:00 2001 From: Michael Fraenkel Date: Tue, 6 Dec 2016 22:31:49 -0500 Subject: [PATCH 1/2] Wait for the port to be ready before starting - wait until the port is ready - verify the container terminated --- test/e2e/portforward.go | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/test/e2e/portforward.go b/test/e2e/portforward.go index b2892cbb4dc..82d020c3b30 100644 --- a/test/e2e/portforward.go +++ b/test/e2e/portforward.go @@ -32,6 +32,7 @@ import ( "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/version" "k8s.io/kubernetes/test/e2e/framework" + testutils "k8s.io/kubernetes/test/utils" . "github.com/onsi/ginkgo" ) @@ -54,6 +55,21 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *v }, Spec: v1.PodSpec{ Containers: []v1.Container{ + { + Name: "readiness", + Image: "gcr.io/google_containers/netexec:1.7", + ReadinessProbe: &v1.Probe{ + Handler: v1.Handler{ + Exec: &v1.ExecAction{ + Command: []string{ + "sh", "-c", "netstat -na | grep LISTEN | grep -v 8080 | grep 80", + }}, + }, + InitialDelaySeconds: 5, + TimeoutSeconds: 60, + PeriodSeconds: 1, + }, + }, { Name: "portforwardtester", Image: "gcr.io/google_containers/portforwardtester:1.2", @@ -86,6 +102,15 @@ func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *v } } +func WaitForTerminatedContainer(f *framework.Framework, pod *v1.Pod, containerName string) error { + return framework.WaitForPodCondition(f.ClientSet, f.Namespace.Name, pod.Name, "container terminated", framework.PodStartTimeout, func(pod *v1.Pod) (bool, error) { + if len(testutils.TerminatedContainers(pod)[containerName]) > 0 { + return true, nil + } + return false, nil + }) +} + type portForwardCommand struct { cmd *exec.Cmd port int @@ -180,7 +205,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { framework.Failf("Couldn't create pod: %v", err) } - if err := f.WaitForPodRunning(pod.Name); err != nil { + if err := f.WaitForPodReady(pod.Name); err != nil { framework.Failf("Pod did not start running: %v", err) } defer func() { @@ -206,8 +231,8 @@ var _ = framework.KubeDescribe("Port forwarding", func() { conn.Close() By("Waiting for the target pod to stop running") - if err := f.WaitForPodNoLongerRunning(pod.Name); err != nil { - framework.Failf("Pod did not stop running: %v", err) + if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil { + framework.Failf("Container did not terminate: %v", err) } By("Verifying logs") @@ -225,7 +250,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { framework.Failf("Couldn't create pod: %v", err) } - if err := f.WaitForPodRunning(pod.Name); err != nil { + if err := f.WaitForPodReady(pod.Name); err != nil { framework.Failf("Pod did not start running: %v", err) } defer func() { @@ -272,8 +297,8 @@ var _ = framework.KubeDescribe("Port forwarding", func() { } By("Waiting for the target pod to stop running") - if err := f.WaitForPodNoLongerRunning(pod.Name); err != nil { - framework.Failf("Pod did not stop running: %v", err) + if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil { + framework.Failf("Container did not terminate: %v", err) } By("Verifying logs") @@ -293,7 +318,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { framework.Failf("Couldn't create pod: %v", err) } - if err := f.WaitForPodRunning(pod.Name); err != nil { + if err := f.WaitForPodReady(pod.Name); err != nil { framework.Failf("Pod did not start running: %v", err) } defer func() { @@ -330,8 +355,8 @@ var _ = framework.KubeDescribe("Port forwarding", func() { } By("Waiting for the target pod to stop running") - if err := f.WaitForPodNoLongerRunning(pod.Name); err != nil { - framework.Failf("Pod did not stop running: %v", err) + if err := WaitForTerminatedContainer(f, pod, "portforwardtester"); err != nil { + framework.Failf("Container did not terminate: %v", err) } By("Verifying logs") From c6d6dcfa1e5bb16073a43b9d13c996bd5d23bb48 Mon Sep 17 00:00:00 2001 From: Michael Fraenkel Date: Wed, 7 Dec 2016 14:00:39 -0500 Subject: [PATCH 2/2] Re-enable flaky tests --- test/e2e/portforward.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/portforward.go b/test/e2e/portforward.go index 82d020c3b30..abbf30627d8 100644 --- a/test/e2e/portforward.go +++ b/test/e2e/portforward.go @@ -199,7 +199,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { f := framework.NewDefaultFramework("port-forwarding") framework.KubeDescribe("With a server that expects a client request", func() { - It("should support a client that connects, sends no data, and disconnects [Conformance] [Flaky]", func() { + It("should support a client that connects, sends no data, and disconnects [Conformance]", func() { By("creating the target pod") pod := pfPod("abc", "1", "1", "1") if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { @@ -244,7 +244,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { verifyLogMessage(logOutput, "Expected to read 3 bytes from client, but got 0 instead") }) - It("should support a client that connects, sends data, and disconnects [Conformance] [Flaky]", func() { + It("should support a client that connects, sends data, and disconnects [Conformance]", func() { By("creating the target pod") pod := pfPod("abc", "10", "10", "100") if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil { @@ -312,7 +312,7 @@ var _ = framework.KubeDescribe("Port forwarding", func() { }) }) framework.KubeDescribe("With a server that expects no client request", func() { - It("should support a client that connects, sends no data, and disconnects [Conformance] [Flaky]", func() { + It("should support a client that connects, sends no data, and disconnects [Conformance]", func() { By("creating the target pod") pod := pfPod("", "10", "10", "100") if _, err := f.ClientSet.Core().Pods(f.Namespace.Name).Create(pod); err != nil {