From 7c8f9976e74b994f19efc8f8803e99a01056f54c Mon Sep 17 00:00:00 2001 From: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:57:47 -0500 Subject: [PATCH] Include command in error from `kubectl` commands Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> (cherry picked from commit 8b82c501d54f59a2a3975d8cc64fb42a8d2127b1) --- test/utils/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/utils/utils.go b/test/utils/utils.go index f6e83c3b..a0f2e781 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -302,10 +302,16 @@ func KubectlWithOutput(args ...string) (string, error) { output, err := kubectlCmd.CombinedOutput() if err != nil { - return string(output), fmt.Errorf("error running kubectl command: %s: %s", output, err.Error()) + // Reformat error to include kubectl command and stderr output + err = fmt.Errorf( + "error running command '%s':\n %s: %s", + strings.Join(kubectlCmd.Args, " "), + output, + err.Error(), + ) } - return string(output), nil + return string(output), err } // GetMetrics execs into the propagator pod and curls the metrics endpoint, filters