Fix the minikube status command.

There were a few cases where stdout wasn't getting flushed correctly,
leading to flakiness in e2e tests.
pull/2891/head
dlorenc 2018-06-12 09:59:10 -07:00 committed by dlorenc
parent 0df67ee4af
commit 79682c2059
2 changed files with 21 additions and 23 deletions

View File

@ -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?

View File

@ -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.Wrapf(err, "running command: %s\n output: %s", cmd, b.Bytes())
return "", errors.Wrap(err, "getting ssh session")
}
return b.String(), nil
defer sess.Close()
b, err := sess.CombinedOutput(cmd)
if err != nil {
return "", errors.Wrapf(err, "running command: %s\n.", cmd)
}
return string(b), nil
}
// Copy copies a file to the remote over SSH.