From 04b1062cbc5eac1a8b70a1094f767f3214fd9ab8 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 17 Feb 2021 11:24:45 +0100 Subject: [PATCH 1/4] e2e createSync() method wait for pod running and ready The user expectections calling this method is that the pod should be ready for the test, however, it only checks that is running, causing timing issues on busy environments. Per example, if the pod is not ready, kube-proxy or other services implementations will not forward traffic to it. --- test/e2e/framework/pod/wait.go | 2 +- test/e2e/framework/pods.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/pod/wait.go b/test/e2e/framework/pod/wait.go index 8124540ba0e..cb107a920b8 100644 --- a/test/e2e/framework/pod/wait.go +++ b/test/e2e/framework/pod/wait.go @@ -357,7 +357,7 @@ func WaitForPodNoLongerRunningInNamespace(c clientset.Interface, podName, namesp return WaitTimeoutForPodNoLongerRunningInNamespace(c, podName, namespace, defaultPodDeletionTimeout) } -// WaitTimeoutForPodReadyInNamespace waits the given timeout diration for the +// WaitTimeoutForPodReadyInNamespace waits the given timeout duration for the // specified pod to be ready and running. func WaitTimeoutForPodReadyInNamespace(c clientset.Interface, podName, namespace string, timeout time.Duration) error { return wait.PollImmediate(poll, timeout, podRunningAndReady(c, podName, namespace)) diff --git a/test/e2e/framework/pods.go b/test/e2e/framework/pods.go index ad20a63fce2..679ac54abf2 100644 --- a/test/e2e/framework/pods.go +++ b/test/e2e/framework/pods.go @@ -96,12 +96,12 @@ func (c *PodClient) Create(pod *v1.Pod) *v1.Pod { return p } -// CreateSync creates a new pod according to the framework specifications, and wait for it to start. +// CreateSync creates a new pod according to the framework specifications, and wait for it to start and be running and ready. func (c *PodClient) CreateSync(pod *v1.Pod) *v1.Pod { namespace := c.f.Namespace.Name p := c.Create(pod) - ExpectNoError(e2epod.WaitForPodNameRunningInNamespace(c.f.ClientSet, p.Name, namespace)) - // Get the newest pod after it becomes running, some status may change after pod created, such as pod ip. + ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(c.f.ClientSet, p.Name, namespace, PodStartTimeout)) + // Get the newest pod after it becomes running and ready, some status may change after pod created, such as pod ip. p, err := c.Get(context.TODO(), p.Name, metav1.GetOptions{}) ExpectNoError(err) return p From 3967bc69421fc42ee12756c02c5c793f735db6ca Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 17 Feb 2021 18:49:19 +0100 Subject: [PATCH 2/4] e2e pod readiness gates wait pod is running --- test/e2e/common/pods.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/common/pods.go b/test/e2e/common/pods.go index e4d61f89bab..828eb995275 100644 --- a/test/e2e/common/pods.go +++ b/test/e2e/common/pods.go @@ -19,6 +19,7 @@ package common import ( "bytes" "context" + "encoding/json" "fmt" "io" "runtime/debug" @@ -28,7 +29,6 @@ import ( "golang.org/x/net/websocket" - "encoding/json" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -813,7 +813,8 @@ var _ = framework.KubeDescribe("Pods", func() { } ginkgo.By("submitting the pod to kubernetes") - podClient.CreateSync(pod) + f.PodClient().Create(pod) + e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) framework.ExpectEqual(podClient.PodIsReady(podName), false, "Expect pod's Ready condition to be false initially.") ginkgo.By(fmt.Sprintf("patching pod status with condition %q to true", readinessGate1)) From 0f1125d8d16bc5320b68b2a318034e4c751d4c77 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 17 Feb 2021 18:49:48 +0100 Subject: [PATCH 3/4] e2e configmap wait for pod is running but not ready --- test/e2e/common/configmap_volume.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/common/configmap_volume.go b/test/e2e/common/configmap_volume.go index 64700f37686..8c84e981844 100644 --- a/test/e2e/common/configmap_volume.go +++ b/test/e2e/common/configmap_volume.go @@ -213,7 +213,8 @@ var _ = ginkgo.Describe("[sig-storage] ConfigMap", func() { }) ginkgo.By("Creating the pod") - f.PodClient().CreateSync(pod) + f.PodClient().Create(pod) + e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) pollLogs1 := func() (string, error) { return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name) From 3d00e9a3030c0c24ef0df00763058578a5afadab Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 17 Feb 2021 22:17:39 +0100 Subject: [PATCH 4/4] e2e emptydir shared volumes wait for running but not ready --- test/e2e/common/empty_dir.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/common/empty_dir.go b/test/e2e/common/empty_dir.go index 9a00f1fef98..5eb36510b2a 100644 --- a/test/e2e/common/empty_dir.go +++ b/test/e2e/common/empty_dir.go @@ -282,7 +282,8 @@ var _ = ginkgo.Describe("[sig-storage] EmptyDir volumes", func() { } ginkgo.By("Creating Pod") - pod = f.PodClient().CreateSync(pod) + f.PodClient().Create(pod) + e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) ginkgo.By("Reading file content from the nginx-container") result := f.ExecShellInContainer(pod.Name, busyBoxMainContainerName, fmt.Sprintf("cat %s", busyBoxMainVolumeFilePath))