From 7ba9ec4b659829b08b38715248abaeb4f5fe90ff 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 | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/k8s/client.go b/k8s/client.go index 25959d52b8..f11d7089ad 100644 --- a/k8s/client.go +++ b/k8s/client.go @@ -453,7 +453,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..cfbc961936 100644 --- a/k8s/exec.go +++ b/k8s/exec.go @@ -73,7 +73,8 @@ 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 + if err := c.execInPodWithWriters(ctx, nil, p, &result.Stdout, &result.Stderr); err != nil { + return result, fmt.Errorf("error with exec request (pod=%s/%s, container=%s): %w", p.Namespace, p.Pod, p.Container, err) + } + return result, nil }