Commit 7d611fe3 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #37624 from deads2k/test-01-text

Automatic merge from submit-queue add wrapper to provide stderr on command errors The go standard library doesn't include stderr in the error message, but in many cases it is present: https://golang.org/src/os/exec/exec.go#L389 . This adds a wrapper to display that information. I've added in it on spot where the kops test is having trouble. If it works well, we can add it elsewhere. @wojtek-t ptal
parents 63161202 8896293c
......@@ -584,7 +584,7 @@ func clusterSize(deploy deployer) (int, error) {
}
o, err := exec.Command("kubectl", "get", "nodes", "--no-headers").Output()
if err != nil {
log.Printf("kubectl get nodes failed: %v", err)
log.Printf("kubectl get nodes failed: %s\n%s", WrapError(err).Error(), string(o))
return -1, err
}
stdout := strings.TrimSpace(string(o))
......@@ -592,6 +592,35 @@ func clusterSize(deploy deployer) (int, error) {
return len(strings.Split(stdout, "\n")), nil
}
// CommandError will provide stderr output (if available) from structured
// exit errors
type CommandError struct {
err error
}
func WrapError(err error) *CommandError {
if err == nil {
return nil
}
return &CommandError{err: err}
}
func (e *CommandError) Error() string {
if e == nil {
return ""
}
exitErr, ok := e.err.(*exec.ExitError)
if !ok {
return e.err.Error()
}
stderr := ""
if exitErr.Stderr != nil {
stderr = string(stderr)
}
return fmt.Sprintf("%q: %q", exitErr.Error(), stderr)
}
func DumpClusterLogs(location string) error {
log.Printf("Dumping cluster logs to: %v", location)
return finishRunning("dump cluster logs", exec.Command("./cluster/log-dump.sh", location))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment