Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #25519 #25537 #25598

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ var _ = Describe("Kubectl client", func() {
It("should support exec", func() {
By("executing a command in the container")
execOutput := runKubectlOrDie("exec", fmt.Sprintf("--namespace=%v", ns), simplePodName, "echo", "running", "in", "container")
if e, a := "running in container", execOutput; e != a {
if e, a := "running in container", strings.TrimSpace(execOutput); e != a {
Failf("Unexpected kubectl exec output. Wanted %q, got %q", e, a)
}

Expand All @@ -219,7 +219,7 @@ var _ = Describe("Kubectl client", func() {
execOutput = newKubectlCommand("exec", fmt.Sprintf("--namespace=%v", ns), "-i", simplePodName, "bash").
withStdinReader(r).
execOrDie()
if e, a := "hi", execOutput; e != a {
if e, a := "hi", strings.TrimSpace(execOutput); e != a {
Failf("Unexpected kubectl exec output. Wanted %q, got %q", e, a)
}
})
Expand Down Expand Up @@ -814,7 +814,11 @@ var _ = Describe("Kubectl client", func() {

It("should be able to retrieve and filter logs [Conformance]", func() {
SkipUnlessServerVersionGTE(extendedPodLogFilterVersion, c)

// Split("something\n", "\n") returns ["something", ""], so
// strip trailing newline first
lines := func(out string) []string {
return strings.Split(strings.TrimRight(out, "\n"), "\n")
}
forEachPod(c, ns, "app", "redis", func(pod api.Pod) {
By("checking for a matching strings")
_, err := lookForStringInLog(ns, pod.Name, containerName, "The server is now ready to accept connections", podStartTimeout)
Expand All @@ -823,18 +827,18 @@ var _ = Describe("Kubectl client", func() {
By("limiting log lines")
out := runKubectlOrDie("log", pod.Name, containerName, nsFlag, "--tail=1")
Expect(len(out)).NotTo(BeZero())
Expect(len(strings.Split(out, "\n"))).To(Equal(1))
Expect(len(lines(out))).To(Equal(1))

By("limiting log bytes")
out = runKubectlOrDie("log", pod.Name, containerName, nsFlag, "--limit-bytes=1")
Expect(len(strings.Split(out, "\n"))).To(Equal(1))
Expect(len(lines(out))).To(Equal(1))
Expect(len(out)).To(Equal(1))

By("exposing timestamps")
out = runKubectlOrDie("log", pod.Name, containerName, nsFlag, "--tail=1", "--timestamps")
lines := strings.Split(out, "\n")
Expect(len(lines)).To(Equal(1))
words := strings.Split(lines[0], " ")
l := lines(out)
Expect(len(l)).To(Equal(1))
words := strings.Split(l[0], " ")
Expect(len(words)).To(BeNumerically(">", 1))
if _, err := time.Parse(time.RFC3339Nano, words[0]); err != nil {
if _, err := time.Parse(time.RFC3339, words[0]); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,7 @@ func (b kubectlBuilder) exec() (string, error) {
return "", fmt.Errorf("Timed out waiting for command %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr)
}
Logf("stderr: %q", stderr.String())
// TODO: trimspace should be unnecessary after switching to use kubectl binary directly
return strings.TrimSpace(stdout.String()), nil
return stdout.String(), nil
}

// runKubectlOrDie is a convenience wrapper over kubectlBuilder
Expand Down