mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
add stderr to command errors
This commit is contained in:
parent
e6c57c6569
commit
8896293cba
31
hack/e2e.go
31
hack/e2e.go
@ -584,7 +584,7 @@ func clusterSize(deploy deployer) (int, error) {
|
|||||||
}
|
}
|
||||||
o, err := exec.Command("kubectl", "get", "nodes", "--no-headers").Output()
|
o, err := exec.Command("kubectl", "get", "nodes", "--no-headers").Output()
|
||||||
if err != nil {
|
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
|
return -1, err
|
||||||
}
|
}
|
||||||
stdout := strings.TrimSpace(string(o))
|
stdout := strings.TrimSpace(string(o))
|
||||||
@ -592,6 +592,35 @@ func clusterSize(deploy deployer) (int, error) {
|
|||||||
return len(strings.Split(stdout, "\n")), nil
|
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 {
|
func DumpClusterLogs(location string) error {
|
||||||
log.Printf("Dumping cluster logs to: %v", location)
|
log.Printf("Dumping cluster logs to: %v", location)
|
||||||
return finishRunning("dump cluster logs", exec.Command("./cluster/log-dump.sh", location))
|
return finishRunning("dump cluster logs", exec.Command("./cluster/log-dump.sh", location))
|
||||||
|
Loading…
Reference in New Issue
Block a user