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 6, 2023
1 parent dacac93 commit 5427e25
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions k8s/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 5427e25

Please sign in to comment.