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 #19350 upstream release 1.1 #19420

Merged
merged 1 commit into from Jan 8, 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
4 changes: 4 additions & 0 deletions pkg/kubelet/prober/prober.go
Expand Up @@ -284,6 +284,10 @@ func (eic execInContainer) CombinedOutput() ([]byte, error) {
return eic.run()
}

func (eic execInContainer) Output() ([]byte, error) {
return nil, fmt.Errorf("unimplemented")
}

func (eic execInContainer) SetDir(dir string) {
//unimplemented
}
9 changes: 7 additions & 2 deletions pkg/probe/exec/exec_test.go
Expand Up @@ -24,14 +24,19 @@ import (
)

type FakeCmd struct {
out []byte
err error
out []byte
stdout []byte
err error
}

func (f *FakeCmd) CombinedOutput() ([]byte, error) {
return f.out, f.err
}

func (f *FakeCmd) Output() ([]byte, error) {
return f.stdout, f.err
}

func (f *FakeCmd) SetDir(dir string) {}

type fakeExitError struct {
Expand Down
28 changes: 21 additions & 7 deletions pkg/util/exec/exec.go
Expand Up @@ -39,6 +39,8 @@ type Cmd interface {
// CombinedOutput runs the command and returns its combined standard output
// and standard error. This follows the pattern of package os/exec.
CombinedOutput() ([]byte, error)
// Output runs the command and returns standard output, but not standard err
Output() ([]byte, error)
SetDir(dir string)
}

Expand Down Expand Up @@ -81,17 +83,29 @@ func (cmd *cmdWrapper) SetDir(dir string) {
func (cmd *cmdWrapper) CombinedOutput() ([]byte, error) {
out, err := (*osexec.Cmd)(cmd).CombinedOutput()
if err != nil {
ee, ok := err.(*osexec.ExitError)
if !ok {
return out, err
}
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var x ExitError = &exitErrorWrapper{ee}
return out, x
return out, handleError(err)
}
return out, nil
}

func (cmd *cmdWrapper) Output() ([]byte, error) {
out, err := (*osexec.Cmd)(cmd).Output()
if err != nil {
return out, handleError(err)
}
return out, nil
}

func handleError(err error) error {
ee, ok := err.(*osexec.ExitError)
if !ok {
return err
}
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var x ExitError = &exitErrorWrapper{ee}
return x
}

// exitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError.
// Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().
type exitErrorWrapper struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/exec/fake_exec.go
Expand Up @@ -75,6 +75,10 @@ func (fake *FakeCmd) CombinedOutput() ([]byte, error) {
return fake.CombinedOutputScript[i]()
}

func (fake *FakeCmd) Output() ([]byte, error) {
return nil, fmt.Errorf("unimplemented")
}

// A simple fake ExitError type.
type FakeExitError struct {
Status int
Expand Down
15 changes: 11 additions & 4 deletions test/e2e/ingress.go
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util"
utilexec "k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/wait"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -187,18 +188,24 @@ func createApp(c *client.Client, ns string, i int) {

// gcloudUnmarshal unmarshals json output of gcloud into given out interface.
func gcloudUnmarshal(resource, regex string, out interface{}) {
args := []string{
// gcloud prints a message to stderr if it has an available update
// so we only look at stdout.
command := []string{
"compute", resource, "list",
fmt.Sprintf("--regex=%v", regex),
fmt.Sprintf("--project=%v", testContext.CloudConfig.ProjectID),
"-q", "--format=json",
}
output, err := exec.Command("gcloud", args...).CombinedOutput()
output, err := exec.Command("gcloud", command...).Output()
if err != nil {
Failf("Error unmarshalling gcloud output: %v", err)
errCode := -1
if exitErr, ok := err.(utilexec.ExitError); ok {
errCode = exitErr.ExitStatus()
}
Logf("Error running gcloud command 'gcloud %s': err: %v, output: %v, status: %d", strings.Join(command, " "), err, string(output), errCode)
}
if err := json.Unmarshal([]byte(output), out); err != nil {
Failf("Error unmarshalling gcloud output for %v: %v, output: %v, command: gcloud %s", resource, err, string(output), strings.Join(args, " "))
Failf("Error unmarshalling gcloud output for %v: %v, output: %v, command: gcloud %s", resource, err, string(output), strings.Join(command, " "))
}
}

Expand Down