mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Merge pull request #38260 from fraenkel/port_forward_readiness
Automatic merge from submit-queue Wait for the port to be ready before starting Fixes the portforward flakes. See #27673 & #27680
This commit is contained in:
commit
99c066efa7
@ -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
|
||||
@ -174,13 +199,13 @@ 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 {
|
||||
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")
|
||||
@ -219,13 +244,13 @@ 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 {
|
||||
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")
|
||||
@ -287,13 +312,13 @@ 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 {
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user