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 #27310 #27448

Merged
merged 1 commit into from
Jun 15, 2016
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
24 changes: 21 additions & 3 deletions test/e2e/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package e2e

import (
"fmt"
"io"
"io/ioutil"
"net"
"os/exec"
Expand All @@ -29,6 +30,7 @@ import (

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/version"

. "github.com/onsi/ginkgo"
)
Expand All @@ -38,7 +40,10 @@ const (
)

// TODO support other ports besides 80
var portForwardRegexp = regexp.MustCompile("Forwarding from 127.0.0.1:([0-9]+) -> 80")
var (
portForwardRegexp = regexp.MustCompile("Forwarding from 127.0.0.1:([0-9]+) -> 80")
portForwardPortToStdOutV = version.MustParse("v1.3.0-alpha.4")
)

func pfPod(expectedClientData, chunks, chunkSize, chunkIntervalMillis string) *api.Pod {
return &api.Pod{
Expand Down Expand Up @@ -123,15 +128,28 @@ func runPortForward(ns, podName string, port int) *portForwardCommand {
// by the port-forward command. We don't want to hard code the port as we have no
// way of guaranteeing we can pick one that isn't in use, particularly on Jenkins.
Logf("starting port-forward command and streaming output")
_, stderr, err := startCmdAndStreamOutput(cmd)
stdout, stderr, err := startCmdAndStreamOutput(cmd)
if err != nil {
Failf("Failed to start port-forward command: %v", err)
}

buf := make([]byte, 128)

// After v1.3.0-alpha.4 (#17030), kubectl port-forward outputs port
// info to stdout, not stderr, so for version-skewed tests, look there
// instead.
var portOutput io.ReadCloser
if useStdOut, err := kubectlVersionGTE(portForwardPortToStdOutV); err != nil {
Failf("Failed to get kubectl version: %v", err)
} else if useStdOut {
portOutput = stdout
} else {
portOutput = stderr
}

var n int
Logf("reading from `kubectl port-forward` command's stderr")
if n, err = stderr.Read(buf); err != nil {
if n, err = portOutput.Read(buf); err != nil {
Failf("Failed to read from kubectl port-forward stderr: %v", err)
}
portForwardOutput := string(buf[:n])
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"os/exec"
"path"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -132,6 +133,9 @@ const (
claimProvisionTimeout = 5 * time.Minute
)

// For parsing Kubectl version for version-skewed testing.
var gitVersionRegexp = regexp.MustCompile("GitVersion:\"(v.+?)\"")

// SubResource proxy should have been functional in v1.0.0, but SubResource
// proxy via tunneling is known to be broken in v1.0. See
// https://github.com/kubernetes/kubernetes/pull/15224#issuecomment-146769463
Expand Down Expand Up @@ -1292,6 +1296,29 @@ func serverVersionGTE(v semver.Version, c discovery.ServerVersionInterface) (boo
return sv.GTE(v), nil
}

// kubectlVersionGTE returns true if the kubectl version is greater than or
// equal to v.
func kubectlVersionGTE(v semver.Version) (bool, error) {
kv, err := kubectlVersion()
if err != nil {
return false, err
}
return kv.GTE(v), nil
}

// kubectlVersion gets the version of kubectl that's currently being used (see
// --kubectl-path in e2e.go to use an alternate kubectl).
func kubectlVersion() (semver.Version, error) {
output := runKubectlOrDie("version", "--client")
matches := gitVersionRegexp.FindStringSubmatch(output)
if len(matches) != 2 {
return semver.Version{}, fmt.Errorf("Could not find kubectl version in output %v", output)
}
// Don't use the full match, as it contains "GitVersion:\"" and a
// trailing "\"". Just use the submatch.
return version.Parse(matches[1])
}

func podsResponding(c *client.Client, ns, name string, wantName bool, pods *api.PodList) error {
By("trying to dial each unique pod")
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
Expand Down