From 5427e259d77c60adabea5f7b2f9ccdbf7df1bebe Mon Sep 17 00:00:00 2001 From: Tom Hadlaw Date: Mon, 6 Nov 2023 11:32:45 -0800 Subject: [PATCH] e2e: add pod/container info in error form exec in pod. When running connectivity tests, it's up to debug logs to provide information on failure errors. This is not always the case, making it hard to understand where to start investigating errors. This adds pod/container to the error message for calls to k8s exec to make it easier to understand where the issue occured. Signed-off-by: Tom Hadlaw --- k8s/client.go | 2 +- k8s/exec.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/k8s/client.go b/k8s/client.go index d42f6a0a11..27d2a3be63 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -437,7 +437,7 @@ func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string } if errString := result.Stderr.String(); errString != "" { - return bytes.Buffer{}, fmt.Errorf("command failed: %s", errString) + return bytes.Buffer{}, fmt.Errorf("command failed (pod=%s/%s, container=%s): %q", namespace, pod, container, errString) } return result.Stdout, nil diff --git a/k8s/exec.go b/k8s/exec.go index 4482656eb7..7bbb37d867 100644 --- a/k8s/exec.go +++ b/k8s/exec.go @@ -74,6 +74,5 @@ func (c *Client) execInPodWithWriters(connCtx, killCmdCtx context.Context, p Exe func (c *Client) execInPod(ctx context.Context, p ExecParameters) (*ExecResult, error) { result := &ExecResult{} err := c.execInPodWithWriters(ctx, nil, p, &result.Stdout, &result.Stderr) - - return result, err + return result, fmt.Errorf("error with exec request (pod=%s/%s, container=%s): %w", p.Namespace, p.Pod, p.Container, err) }