From 5889cb0fe4a1ff24f2cc01491ae622988b34d4f5 Mon Sep 17 00:00:00 2001 From: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:41:03 -0500 Subject: [PATCH] Return shell errors with output Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com> (cherry picked from commit 5a8e5b6170dc0e3b18b722561089d4453ecf8e7e) --- test/utils/utils.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/utils/utils.go b/test/utils/utils.go index 6171aaed..f6e83c3b 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -298,11 +298,14 @@ func Kubectl(args ...string) { // KubectlWithOutput execute kubectl cli and return output and error func KubectlWithOutput(args ...string) (string, error) { - output, err := exec.Command("kubectl", args...).CombinedOutput() - //nolint:forbidigo - fmt.Println(string(output)) + kubectlCmd := exec.Command("kubectl", args...) - return string(output), err + output, err := kubectlCmd.CombinedOutput() + if err != nil { + return string(output), fmt.Errorf("error running kubectl command: %s: %s", output, err.Error()) + } + + return string(output), nil } // GetMetrics execs into the propagator pod and curls the metrics endpoint, filters