mirror of https://github.com/k3s-io/k3s
Improve error reporting a little in ingress e2e.
Also add Output() to the util/exec Cmd interface.pull/6/head
parent
8f4d801368
commit
07b3ab720d
|
@ -214,6 +214,10 @@ func (eic execInContainer) CombinedOutput() ([]byte, error) {
|
||||||
return eic.run()
|
return eic.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (eic execInContainer) Output() ([]byte, error) {
|
||||||
|
return nil, fmt.Errorf("unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (eic execInContainer) SetDir(dir string) {
|
func (eic execInContainer) SetDir(dir string) {
|
||||||
//unimplemented
|
//unimplemented
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeCmd struct {
|
type FakeCmd struct {
|
||||||
out []byte
|
out []byte
|
||||||
err error
|
stdout []byte
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakeCmd) CombinedOutput() ([]byte, error) {
|
func (f *FakeCmd) CombinedOutput() ([]byte, error) {
|
||||||
return f.out, f.err
|
return f.out, f.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FakeCmd) Output() ([]byte, error) {
|
||||||
|
return f.stdout, f.err
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FakeCmd) SetDir(dir string) {}
|
func (f *FakeCmd) SetDir(dir string) {}
|
||||||
|
|
||||||
type fakeExitError struct {
|
type fakeExitError struct {
|
||||||
|
|
|
@ -42,6 +42,8 @@ type Cmd interface {
|
||||||
// CombinedOutput runs the command and returns its combined standard output
|
// CombinedOutput runs the command and returns its combined standard output
|
||||||
// and standard error. This follows the pattern of package os/exec.
|
// and standard error. This follows the pattern of package os/exec.
|
||||||
CombinedOutput() ([]byte, error)
|
CombinedOutput() ([]byte, error)
|
||||||
|
// Output runs the command and returns standard output, but not standard err
|
||||||
|
Output() ([]byte, error)
|
||||||
SetDir(dir string)
|
SetDir(dir string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,21 +86,33 @@ func (cmd *cmdWrapper) SetDir(dir string) {
|
||||||
func (cmd *cmdWrapper) CombinedOutput() ([]byte, error) {
|
func (cmd *cmdWrapper) CombinedOutput() ([]byte, error) {
|
||||||
out, err := (*osexec.Cmd)(cmd).CombinedOutput()
|
out, err := (*osexec.Cmd)(cmd).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ee, ok := err.(*osexec.ExitError); ok {
|
return out, handleError(err)
|
||||||
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
|
|
||||||
var x ExitError = &exitErrorWrapper{ee}
|
|
||||||
return out, x
|
|
||||||
}
|
|
||||||
if ee, ok := err.(*osexec.Error); ok {
|
|
||||||
if ee.Err == osexec.ErrNotFound {
|
|
||||||
return out, ErrExecutableNotFound
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out, err
|
|
||||||
}
|
}
|
||||||
return out, nil
|
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 {
|
||||||
|
if ee, ok := err.(*osexec.ExitError); ok {
|
||||||
|
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
|
||||||
|
var x ExitError = &exitErrorWrapper{ee}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
if ee, ok := err.(*osexec.Error); ok {
|
||||||
|
if ee.Err == osexec.ErrNotFound {
|
||||||
|
return ErrExecutableNotFound
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// exitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError.
|
// exitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError.
|
||||||
// Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().
|
// Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().
|
||||||
type exitErrorWrapper struct {
|
type exitErrorWrapper struct {
|
||||||
|
|
|
@ -75,6 +75,10 @@ func (fake *FakeCmd) CombinedOutput() ([]byte, error) {
|
||||||
return fake.CombinedOutputScript[i]()
|
return fake.CombinedOutputScript[i]()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeCmd) Output() ([]byte, error) {
|
||||||
|
return nil, fmt.Errorf("unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
// A simple fake ExitError type.
|
// A simple fake ExitError type.
|
||||||
type FakeExitError struct {
|
type FakeExitError struct {
|
||||||
Status int
|
Status int
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/labels"
|
"k8s.io/kubernetes/pkg/labels"
|
||||||
|
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
|
|
||||||
|
@ -190,12 +191,21 @@ func createApp(c *client.Client, ns string, i int) {
|
||||||
|
|
||||||
// gcloudUnmarshal unmarshals json output of gcloud into given out interface.
|
// gcloudUnmarshal unmarshals json output of gcloud into given out interface.
|
||||||
func gcloudUnmarshal(resource, regex, project string, out interface{}) {
|
func gcloudUnmarshal(resource, regex, project string, out interface{}) {
|
||||||
output, err := exec.Command("gcloud", "compute", resource, "list",
|
// 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("--regex=%v", regex),
|
||||||
fmt.Sprintf("--project=%v", project),
|
fmt.Sprintf("--project=%v", project),
|
||||||
"-q", "--format=json").CombinedOutput()
|
"-q", "--format=json",
|
||||||
|
}
|
||||||
|
output, err := exec.Command("gcloud", command...).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logf("Error unmarshalling gcloud err: %v, output: %v", err, string(output))
|
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 {
|
if err := json.Unmarshal([]byte(output), out); err != nil {
|
||||||
Logf("Error unmarshalling gcloud output for %v: %v, output: %v", resource, err, string(output))
|
Logf("Error unmarshalling gcloud output for %v: %v, output: %v", resource, err, string(output))
|
||||||
|
|
Loading…
Reference in New Issue