Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func getProxiedSSHClient(controlPlaneEndpoint, hostname, port string, ioTimeout

// execOnHost runs the specified command directly on a node's host, using a SSH connection
// proxied through a control plane host and copies the output to a file.
func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Duration, f io.StringWriter, command string,
func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Duration, f io.Writer, command string,
args ...string) error {
client, err := getProxiedSSHClient(controlPlaneEndpoint, hostname, port, ioTimeout)
if err != nil {
Expand All @@ -502,16 +502,14 @@ func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Dura
defer session.Close()

// Run the command and write the captured stdout to the file
var stdoutBuf bytes.Buffer
session.Stdout = &stdoutBuf
var stderrBuf bytes.Buffer
session.Stdout = f
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of the intermediate stdoutBuf is a drive-by optimization to save us from holding onto the entire file content in memory before writing it to the file.

session.Stderr = &stderrBuf
if len(args) > 0 {
command += " " + strings.Join(args, " ")
}
if err = session.Run(command); err != nil {
return errors.Wrapf(err, "running command \"%s\"", command)
}
if _, err = f.WriteString(stdoutBuf.String()); err != nil {
return errors.Wrap(err, "writing output to file")
return fmt.Errorf("running command %q: %w, stderr: %s", command, err, strings.TrimSpace(stderrBuf.String()))
}

return nil
Expand Down