Skip to content

Commit

Permalink
clusterctl/kind: return stdout and not combined output
Browse files Browse the repository at this point in the history
Ideally only the stdout of kind commands should be captured
and returned, in case kind commands also contain stderr.

Fixes a recent bug where the kind command "get kubeconfig-path"
started printing a deprecation message on stderr.
  • Loading branch information
neolit123 committed Nov 21, 2019
1 parent 08b2959 commit 1f60998
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/clusterctl/clusterdeployer/bootstrap/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package kind

import (
"bytes"
"fmt"
"io/ioutil"
"os/exec"
Expand Down Expand Up @@ -67,14 +68,24 @@ func WithOptions(options []string) *Kind {

var execFunc = func(args ...string) (string, error) {
const executable = "kind"
klog.V(3).Infof("Running: %v %v", executable, args)
joinedArgs := strings.Join(args, " ")
klog.V(3).Infof("Running: %v %v", executable, joinedArgs)

cmd := exec.Command(executable, args...)
cmdOut, err := cmd.CombinedOutput()
klog.V(2).Infof("Ran: %v %v Output: %v", executable, args, string(cmdOut))
var bufErr, bufOut bytes.Buffer
cmd.Stdout = &bufOut
cmd.Stderr = &bufErr

commandMessage := fmt.Sprintf("%v %v\nStdout:\n%v\nStderr:\n%v",
executable, joinedArgs, bufOut.String(), bufErr.String())

err := cmd.Run()
if err != nil {
err = errors.Wrapf(err, "error running command '%v %v'", executable, strings.Join(args, " "))
return "", errors.Wrapf(err, "error running command: %s", commandMessage)
}
return string(cmdOut), err

klog.V(2).Infof("Ran: %s", commandMessage)
return bufOut.String(), err
}

func (k *Kind) Create() error {
Expand Down

0 comments on commit 1f60998

Please sign in to comment.