mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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
This commit is contained in:
commit
7d611fe32b
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()
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user