From 6db2dadc87961226cb96a6562cc4620c560ad924 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Mon, 8 Oct 2018 16:52:25 -0700 Subject: [PATCH] Fixes webhook test failures The test "Should be able to deny attaching pod" can randomly fail because it never waits for the pod to enter a "Running" state. Because of this, the "kubectl attach" command can potentially fail, if the pod is not in the correct state. Additionally, if the "kubectl attach" actually manages to attach, then the test will hang. The command should be executed with a timeout. --- test/e2e/apimachinery/webhook.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/e2e/apimachinery/webhook.go b/test/e2e/apimachinery/webhook.go index f339fd8378..b71b174dfb 100644 --- a/test/e2e/apimachinery/webhook.go +++ b/test/e2e/apimachinery/webhook.go @@ -708,9 +708,13 @@ func testAttachingPodWebhook(f *framework.Framework) { pod := toBeAttachedPod(f) _, err := client.CoreV1().Pods(f.Namespace.Name).Create(pod) Expect(err).To(BeNil()) + err = framework.WaitForPodNameRunningInNamespace(client, pod.Name, f.Namespace.Name) + Expect(err).NotTo(HaveOccurred()) By("'kubectl attach' the pod, should be denied by the webhook") - _, err = framework.NewKubectlCommand("attach", fmt.Sprintf("--namespace=%v", f.Namespace.Name), pod.Name, "-i", "-c=container1").Exec() + timer := time.NewTimer(30 * time.Second) + defer timer.Stop() + _, err = framework.NewKubectlCommand("attach", fmt.Sprintf("--namespace=%v", f.Namespace.Name), pod.Name, "-i", "-c=container1").WithTimeout(timer.C).Exec() Expect(err).NotTo(BeNil()) if e, a := "attaching to pod 'to-be-attached-pod' is not allowed", err.Error(); !strings.Contains(a, e) { framework.Failf("unexpected 'kubectl attach' error message. expected to contain %q, got %q", e, a)