Skip to content

Commit

Permalink
e2e: add pod/container info in error form exec in pod.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tommyp1ckles committed Nov 22, 2023
1 parent 91812da commit b9a93b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions k8s/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b9a93b8

Please sign in to comment.