@@ -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 {
@@ -503,14 +503,16 @@ func execOnHost(controlPlaneEndpoint, hostname, port string, ioTimeout time.Dura
503503
504504 // Run the command and write the captured stdout to the file
505505 var stdoutBuf bytes.Buffer
506+ var stderrBuf bytes.Buffer
506507 session .Stdout = & stdoutBuf
508+ session .Stderr = & stderrBuf
507509 if len (args ) > 0 {
508510 command += " " + strings .Join (args , " " )
509511 }
510512 if err = session .Run (command ); err != nil {
511- return errors . Wrapf ( err , "running command \" %s \" " , command )
513+ return fmt . Errorf ( "running command %q: %w, stderr: %s" , command , err , strings . TrimSpace ( stderrBuf . String ()) )
512514 }
513- if _ , err = f . WriteString ( stdoutBuf . String () ); err != nil {
515+ if _ , err = io . Copy ( f , & stdoutBuf ); err != nil {
514516 return errors .Wrap (err , "writing output to file" )
515517 }
516518
0 commit comments