@@ -488,7 +488,7 @@ func getProxiedSSHClient(controlPlaneEndpoint, hostname, port string, ioTimeout
488
488
489
489
// execOnHost runs the specified command directly on a node's host, using a SSH connection
490
490
// proxied through a control plane host and copies the output to a file.
491
- func execOnHost (controlPlaneEndpoint , hostname , port string , ioTimeout time.Duration , f io.StringWriter , command string ,
491
+ func execOnHost (controlPlaneEndpoint , hostname , port string , ioTimeout time.Duration , f io.Writer , command string ,
492
492
args ... string ) error {
493
493
client , err := getProxiedSSHClient (controlPlaneEndpoint , hostname , port , ioTimeout )
494
494
if err != nil {
@@ -502,16 +502,14 @@ func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Dura
502
502
defer session .Close ()
503
503
504
504
// Run the command and write the captured stdout to the file
505
- var stdoutBuf bytes.Buffer
506
- session .Stdout = & stdoutBuf
505
+ var stderrBuf bytes.Buffer
506
+ session .Stdout = f
507
+ session .Stderr = & stderrBuf
507
508
if len (args ) > 0 {
508
509
command += " " + strings .Join (args , " " )
509
510
}
510
511
if err = session .Run (command ); err != nil {
511
- return errors .Wrapf (err , "running command \" %s\" " , command )
512
- }
513
- if _ , err = f .WriteString (stdoutBuf .String ()); err != nil {
514
- return errors .Wrap (err , "writing output to file" )
512
+ return fmt .Errorf ("running command %q: %w, stderr: %s" , command , err , strings .TrimSpace (stderrBuf .String ()))
515
513
}
516
514
517
515
return nil
0 commit comments