e2e: Dump stdout and describe ksvc (#659)

if the service create/update command execution failed
This commit is contained in:
Navid Shaikh 2020-02-12 23:11:22 +05:30 committed by GitHub
parent e0319177d6
commit 3019f6813b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -225,8 +225,10 @@ func runCLIWithOpts(cli string, args []string, opts runOpts, logger Logger) (str
err := cmd.Run()
if err != nil {
err = fmt.Errorf("Execution error: stderr: '%s' error: '%s'", stderr.String(), err)
if !opts.AllowError {
fmt.Println("================[[Error]]=================")
fmt.Println(stdout.String())
dumpKsvc(args, logger)
logger.Fatalf("Failed to successfully execute '%s': %v", cmdCLIDesc(cli, args), err)
}
}
@ -234,6 +236,20 @@ func runCLIWithOpts(cli string, args []string, opts runOpts, logger Logger) (str
return stdout.String(), err
}
func dumpKsvc(args []string, logger Logger) {
if args[0] == "service" {
opts := runOpts{AllowError: true}
ns := args[len(args)-1]
out, err := runCLIWithOpts("kubectl", []string{"-n", ns, "describe", "ksvc", args[2]}, opts, logger)
fmt.Println(err)
fmt.Println(out)
out, err = runCLIWithOpts("kubectl", []string{"-n", ns, "get", "ksvc", args[2], "-oyaml"}, opts, logger)
fmt.Println(err)
fmt.Println(out)
fmt.Println("================[[Error]]=================")
}
}
func cmdCLIDesc(cli string, args []string) string {
return fmt.Sprintf("%s %s", cli, strings.Join(args, " "))
}