diff --git a/pkg/drivers/none/none.go b/pkg/drivers/none/none.go index da282af966..f90effda0c 100644 --- a/pkg/drivers/none/none.go +++ b/pkg/drivers/none/none.go @@ -220,19 +220,22 @@ func (d *Driver) RunSSHCommandFromDriver() error { } // stopKubelet idempotently stops the kubelet -func stopKubelet(exec command.Runner) error { +func stopKubelet(cr command.Runner) error { glog.Infof("stopping kubelet.service ...") stop := func() error { - cmdStop := "sudo systemctl stop kubelet.service" - cmdCheck := "sudo systemctl show -p SubState kubelet" - err := exec.Run(cmdStop) + cmdStop := command.ExecCmd("sudo systemctl stop kubelet.service") + rr, err := cr.RunCmd(cmdStop) if err != nil { - glog.Errorf("temporary error for %q : %v", cmdStop, err) + glog.Errorf("temporary error for %q : %v", rr.Command(), err) } + var out bytes.Buffer - errStatus := exec.CombinedOutputTo(cmdCheck, &out) - if errStatus != nil { - glog.Errorf("temporary error: for %q : %v", cmdCheck, errStatus) + cmdCheck := command.ExecCmd("sudo systemctl show -p SubState kubelet") + cmdCheck.Stdout = &out + cmdCheck.Stderr = &out + rr, err = cr.RunCmd(cmdCheck) + if err != nil { + glog.Errorf("temporary error: for %q : %v output: %q", cmdCheck, err, rr.Output()) } if !strings.Contains(out.String(), "dead") && !strings.Contains(out.String(), "failed") { return fmt.Errorf("unexpected kubelet state: %q", out) diff --git a/pkg/minikube/command/fake_runner.go b/pkg/minikube/command/fake_runner.go index b4e5a4d34e..ed92409570 100644 --- a/pkg/minikube/command/fake_runner.go +++ b/pkg/minikube/command/fake_runner.go @@ -54,18 +54,29 @@ func (f *FakeCommandRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) { start := time.Now() - out, ok := f.cmdMap.Load(cmd.Args) - rr.Stderr = bytes.NewBuffer([]byte(out.(string))) // converting fake output string to a buffer + out, ok := f.cmdMap.Load(strings.Join(cmd.Args, " ")) + buf := new(bytes.Buffer) // creating a buffer reader to convert out to rr.stdout + outStr := "" + if out != nil { + outStr = out.(string) + } + _, err := buf.WriteString(outStr) + if err != nil { + return rr, errors.Wrap(err, "Writing outStr to FakeCommandRunner's buffer") + } + rr.Stdout = buf + rr.Stderr = buf elapsed := time.Since(start) + if ok { // Reduce log spam if elapsed > (1 * time.Second) { glog.Infof("(FakeCommandRunner) Done: %v: (%s)", rr.Command(), elapsed) } } else { - glog.Infof("(FakeCommandRunner) Non-zero exit: %v: (%s)\n%s", rr.Command(), elapsed, rr.Output()) - return rr, fmt.Errorf("unavailable command: %s", strings.Join(cmd.Args, " ")) + glog.Infof("(FakeCommandRunner) Non-zero exit: %v: (%s)\n%s", rr.Command(), elapsed, out) + return rr, fmt.Errorf("unavailable command: %s", rr.Command()) } return rr, nil }