diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index b4c28ef3e37..eb5a6229eed 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -2169,18 +2169,20 @@ func (b kubectlBuilder) WithStdinReader(reader io.Reader) *kubectlBuilder { return &b } -func (b kubectlBuilder) ExecOrDie() (string, string) { - stdout, stderr, err := b.Exec() +func (b kubectlBuilder) ExecOrDie() string { + str, err := b.Exec() + Logf("stdout: %q", str) // In case of i/o timeout error, try talking to the apiserver again after 2s before dying. // Note that we're still dying after retrying so that we can get visibility to triage it further. if isTimeout(err) { Logf("Hit i/o timeout error, talking to the server 2s later to see if it's temporary.") time.Sleep(2 * time.Second) - _, retryErr := RunKubectl("version") + retryStr, retryErr := RunKubectl("version") + Logf("stdout: %q", retryStr) Logf("err: %v", retryErr) } Expect(err).NotTo(HaveOccurred()) - return stdout, stderr + return str } func isTimeout(err error) bool { @@ -2197,14 +2199,14 @@ func isTimeout(err error) bool { return false } -func (b kubectlBuilder) Exec() (string, string, error) { +func (b kubectlBuilder) Exec() (string, error) { var stdout, stderr bytes.Buffer cmd := b.cmd cmd.Stdout, cmd.Stderr = &stdout, &stderr Logf("Running '%s %s'", cmd.Path, strings.Join(cmd.Args[1:], " ")) // skip arg[0] as it is printed separately if err := cmd.Start(); err != nil { - return "", "", fmt.Errorf("error starting %v:\nCommand stdout:\n%v\nstderr:\n%v\nerror:\n%v\n", cmd, cmd.Stdout, cmd.Stderr, err) + return "", fmt.Errorf("error starting %v:\nCommand stdout:\n%v\nstderr:\n%v\nerror:\n%v\n", cmd, cmd.Stdout, cmd.Stderr, err) } errCh := make(chan error, 1) go func() { @@ -2218,39 +2220,32 @@ func (b kubectlBuilder) Exec() (string, string, error) { Logf("rc: %d", rc) rc = int(ee.Sys().(syscall.WaitStatus).ExitStatus()) } - return "", "", uexec.CodeExitError{ + return "", uexec.CodeExitError{ Err: fmt.Errorf("error running %v:\nCommand stdout:\n%v\nstderr:\n%v\nerror:\n%v\n", cmd, cmd.Stdout, cmd.Stderr, err), Code: rc, } } case <-b.timeout: b.cmd.Process.Kill() - return "", "", fmt.Errorf("timed out waiting for command %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr) + return "", fmt.Errorf("timed out waiting for command %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr) } - - stderrString := stderr.String() - stdoutString := stdout.String() - Logf("stderr: %q", stderrString) - Logf("stdout: %q", stdoutString) - return stdoutString, stderrString, nil + Logf("stderr: %q", stderr.String()) + return stdout.String(), nil } // RunKubectlOrDie is a convenience wrapper over kubectlBuilder func RunKubectlOrDie(args ...string) string { - stdout, _ := NewKubectlCommand(args...).ExecOrDie() - return stdout + return NewKubectlCommand(args...).ExecOrDie() } // RunKubectl is a convenience wrapper over kubectlBuilder func RunKubectl(args ...string) (string, error) { - stdout, _, err := NewKubectlCommand(args...).Exec() - return stdout, err + return NewKubectlCommand(args...).Exec() } // RunKubectlOrDieInput is a convenience wrapper over kubectlBuilder that takes input to stdin func RunKubectlOrDieInput(data string, args ...string) string { - stdout, _ := NewKubectlCommand(args...).WithStdinData(data).ExecOrDie() - return stdout + return NewKubectlCommand(args...).WithStdinData(data).ExecOrDie() } func StartCmdAndStreamOutput(cmd *exec.Cmd) (stdout, stderr io.ReadCloser, err error) { diff --git a/test/e2e/kubectl.go b/test/e2e/kubectl.go index ac272359f4a..7f7bfe48d4f 100644 --- a/test/e2e/kubectl.go +++ b/test/e2e/kubectl.go @@ -297,7 +297,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { } By("executing a command in the container with noninteractive stdin") - execOutput, _ = framework.NewKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "cat"). + execOutput = framework.NewKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "cat"). WithStdinData("abcd1234"). ExecOrDie() if e, a := "abcd1234", execOutput; e != a { @@ -313,7 +313,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { defer closer.Close() By("executing a command in the container with pseudo-interactive stdin") - execOutput, _ = framework.NewKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "bash"). + execOutput = framework.NewKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "bash"). WithStdinReader(r). ExecOrDie() if e, a := "hi", strings.TrimSpace(execOutput); e != a { @@ -338,7 +338,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { for _, proxyVar := range []string{"https_proxy", "HTTPS_PROXY"} { proxyLogs.Reset() By("Running kubectl via an HTTP proxy using " + proxyVar) - output, _ := framework.NewKubectlCommand(fmt.Sprintf("--namespace=%s", ns), "exec", "nginx", "echo", "running", "in", "container"). + output := framework.NewKubectlCommand(fmt.Sprintf("--namespace=%s", ns), "exec", "nginx", "echo", "running", "in", "container"). WithEnv(append(os.Environ(), fmt.Sprintf("%s=%s", proxyVar, proxyAddr))). ExecOrDie() @@ -363,40 +363,40 @@ var _ = framework.KubeDescribe("Kubectl client", func() { nsFlag := fmt.Sprintf("--namespace=%v", ns) By("execing into a container with a successful command") - _, _, err := framework.NewKubectlCommand(nsFlag, "exec", "nginx", "--", "/bin/sh", "-c", "exit 0").Exec() + _, err := framework.NewKubectlCommand(nsFlag, "exec", "nginx", "--", "/bin/sh", "-c", "exit 0").Exec() ExpectNoError(err) By("execing into a container with a failing command") - _, _, err = framework.NewKubectlCommand(nsFlag, "exec", "nginx", "--", "/bin/sh", "-c", "exit 42").Exec() + _, err = framework.NewKubectlCommand(nsFlag, "exec", "nginx", "--", "/bin/sh", "-c", "exit 42").Exec() ee, ok := err.(uexec.ExitError) Expect(ok).To(Equal(true)) Expect(ee.ExitStatus()).To(Equal(42)) By("running a successful command") - _, _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "success", "--", "/bin/sh", "-c", "exit 0").Exec() + _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "success", "--", "/bin/sh", "-c", "exit 0").Exec() ExpectNoError(err) By("running a failing command") - _, _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-1", "--", "/bin/sh", "-c", "exit 42").Exec() + _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-1", "--", "/bin/sh", "-c", "exit 42").Exec() ee, ok = err.(uexec.ExitError) Expect(ok).To(Equal(true)) Expect(ee.ExitStatus()).To(Equal(42)) By("running a failing command without --restart=Never") - _, _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "failure-2", "--", "/bin/sh", "-c", "cat && exit 42"). + _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "failure-2", "--", "/bin/sh", "-c", "cat && exit 42"). WithStdinData("abcd1234"). Exec() ExpectNoError(err) By("running a failing command without --restart=Never, but with --rm") - _, _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "--rm", "failure-3", "--", "/bin/sh", "-c", "cat && exit 42"). + _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=OnFailure", "--rm", "failure-3", "--", "/bin/sh", "-c", "cat && exit 42"). WithStdinData("abcd1234"). Exec() ExpectNoError(err) framework.WaitForPodToDisappear(f.Client, ns, "failure-3", labels.Everything(), 2*time.Second, wait.ForeverTestTimeout) By("running a failing command with --leave-stdin-open") - _, _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-4", "--leave-stdin-open", "--", "/bin/sh", "-c", "exit 42"). + _, err = framework.NewKubectlCommand(nsFlag, "run", "-i", "--image="+busyboxImage, "--restart=Never", "failure-4", "--leave-stdin-open", "--", "/bin/sh", "-c", "exit 42"). WithStdinData("abcd1234"). Exec() ExpectNoError(err) @@ -409,7 +409,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { nsFlag := fmt.Sprintf("--namespace=%v", ns) By("executing a command with run and attach with stdin") - runOutput, _ := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). + runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). WithStdinData("abcd1234"). ExecOrDie() Expect(runOutput).To(ContainSubstring("abcd1234")) @@ -417,7 +417,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { Expect(c.Extensions().Jobs(ns).Delete("run-test", nil)).To(BeNil()) By("executing a command with run and attach without stdin") - runOutput, _ = framework.NewKubectlCommand(fmt.Sprintf("--namespace=%v", ns), "run", "run-test-2", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "cat && echo 'stdin closed'"). + runOutput = framework.NewKubectlCommand(fmt.Sprintf("--namespace=%v", ns), "run", "run-test-2", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "cat && echo 'stdin closed'"). WithStdinData("abcd1234"). ExecOrDie() Expect(runOutput).ToNot(ContainSubstring("abcd1234")) @@ -425,7 +425,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { Expect(c.Extensions().Jobs(ns).Delete("run-test-2", nil)).To(BeNil()) By("executing a command with run and attach with stdin with open stdin should remain running") - runOutput, _ = framework.NewKubectlCommand(nsFlag, "run", "run-test-3", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). + runOutput = framework.NewKubectlCommand(nsFlag, "run", "run-test-3", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). WithStdinData("abcd1234\n"). ExecOrDie() Expect(runOutput).ToNot(ContainSubstring("stdin closed")) @@ -1175,7 +1175,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() { By("executing a command with run --rm and attach with stdin") t := time.NewTimer(runJobTimeout) defer t.Stop() - runOutput, _ := framework.NewKubectlCommand(nsFlag, "run", jobName, "--image="+busyboxImage, "--rm=true", "--generator=job/v1", "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). + runOutput := framework.NewKubectlCommand(nsFlag, "run", jobName, "--image="+busyboxImage, "--rm=true", "--generator=job/v1", "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'"). WithStdinData("abcd1234"). WithTimeout(t.C). ExecOrDie() @@ -1189,28 +1189,6 @@ var _ = framework.KubeDescribe("Kubectl client", func() { }) }) - framework.KubeDescribe("Kubectl run --quiet job", func() { - jobName := "e2e-test-quiet-busybox-job" - - It("should not output anything except the command when --quiet is set", func() { - nsFlag := fmt.Sprintf("--namespace=%v", ns) - - // The rkt runtime doesn't support attach, see #23335 - framework.SkipIfContainerRuntimeIs("rkt") - framework.SkipUnlessServerVersionGTE(jobsVersion, c) - - By("executing a command with run --rm and attach with stdin") - t := time.NewTimer(runJobTimeout) - defer t.Stop() - // TODO: remove sleep when attach works immediately - stdout, stderr := framework.NewKubectlCommand(nsFlag, "run", jobName, "--image="+busyboxImage, "--quiet", "--rm", "--restart=Never", "--stdin", "--attach", "--generator=job/v1", "--", "sh", "-c", "sleep 3; echo output; sleep 3"). - WithTimeout(t.C). - ExecOrDie() - Expect(stdout).To(Equal("output\n"), "Checking STDOUT contains only our output") - Expect(stderr).To(Equal(""), "Checking STDERR is empty") - }) - }) - framework.KubeDescribe("Proxy server", func() { // TODO: test proxy options (static, prefix, etc) It("should support proxy with --port 0 [Conformance]", func() {