From 8606e6d5919858aeef38b5f8951ba4a460f7ab92 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Tue, 12 Jun 2018 09:59:10 -0700 Subject: [PATCH] Fix the minikube status command. There were a few cases where stdout wasn't getting flushed correctly, leading to flakiness in e2e tests. --- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 13 ++++---- pkg/minikube/bootstrapper/ssh_runner.go | 31 ++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 55e996aefbde..7f4b36d6fe6f 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -69,16 +69,19 @@ func NewKubeadmBootstrapper(api libmachine.API) (*KubeadmBootstrapper, error) { //TODO(r2d4): This should most likely check the health of the apiserver func (k *KubeadmBootstrapper) GetClusterStatus() (string, error) { - statusCmd := `sudo systemctl is-active kubelet &>/dev/null && echo "Running" || echo "Stopped"` + statusCmd := `sudo systemctl is-active kubelet` status, err := k.c.CombinedOutput(statusCmd) if err != nil { return "", errors.Wrap(err, "getting status") } - status = strings.TrimSpace(status) - if status == state.Running.String() || status == state.Stopped.String() { - return status, nil + s := strings.TrimSpace(status) + switch s { + case "active": + return state.Running.String(), nil + case "inactive": + return state.Stopped.String(), nil } - return "", fmt.Errorf("Error: Unrecognized output from ClusterStatus: %s", status) + return state.Error.String(), nil } // TODO(r2d4): Should this aggregate all the logs from the control plane? diff --git a/pkg/minikube/bootstrapper/ssh_runner.go b/pkg/minikube/bootstrapper/ssh_runner.go index 0aa56704dae5..96898e2d6587 100644 --- a/pkg/minikube/bootstrapper/ssh_runner.go +++ b/pkg/minikube/bootstrapper/ssh_runner.go @@ -17,7 +17,6 @@ limitations under the License. package bootstrapper import ( - "bytes" "fmt" "io" "path" @@ -67,33 +66,29 @@ func (s *SSHRunner) Run(cmd string) error { // CombinedOutputTo runs the command and stores both command // output and error to out. func (s *SSHRunner) CombinedOutputTo(cmd string, out io.Writer) error { - glog.Infoln("Run with output:", cmd) - sess, err := s.c.NewSession() - if err != nil { - return errors.Wrap(err, "getting ssh session") - } - defer sess.Close() - - sess.Stdout = out - sess.Stderr = out - - err = sess.Run(cmd) + b, err := s.CombinedOutput(cmd) if err != nil { return errors.Wrapf(err, "running command: %s\n.", cmd) } - - return nil + _, err = out.Write([]byte(b)) + return err } // CombinedOutput runs the command on the remote and returns its combined // standard output and standard error. func (s *SSHRunner) CombinedOutput(cmd string) (string, error) { - var b bytes.Buffer - err := s.CombinedOutputTo(cmd, &b) + glog.Infoln("Run with output:", cmd) + sess, err := s.c.NewSession() + if err != nil { + return "", errors.Wrap(err, "getting ssh session") + } + defer sess.Close() + + b, err := sess.CombinedOutput(cmd) if err != nil { - return "", errors.Wrapf(err, "running command: %s\n output: %s", cmd, b.Bytes()) + return "", errors.Wrapf(err, "running command: %s\n.", cmd) } - return b.String(), nil + return string(b), nil } // Copy copies a file to the remote over SSH.