Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the minikube status command. #2894

Merged
merged 1 commit into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
31 changes: 13 additions & 18 deletions pkg/minikube/bootstrapper/ssh_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package bootstrapper

import (
"bytes"
"fmt"
"io"
"path"
Expand Down Expand Up @@ -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.
Expand Down