@@ -488,7 +488,7 @@ func getProxiedSSHClient(controlPlaneEndpoint, hostname, port string, ioTimeout
488488
489489// execOnHost runs the specified command directly on a node's host, using a SSH connection
490490// 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 ,
492492 args ... string ) error {
493493 client , err := getProxiedSSHClient (controlPlaneEndpoint , hostname , port , ioTimeout )
494494 if err != nil {
@@ -502,16 +502,14 @@ func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Dura
502502 defer session .Close ()
503503
504504 // 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
507508 if len (args ) > 0 {
508509 command += " " + strings .Join (args , " " )
509510 }
510511 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 ()))
515513 }
516514
517515 return nil
0 commit comments