Merge pull request #2121 from ulyssessouza/master
#1944 Add the 3 services status in 'minikube status' exit status.pull/2135/head
commit
69fc158ce8
|
@ -42,23 +42,34 @@ type Status struct {
|
|||
KubeconfigStatus string
|
||||
}
|
||||
|
||||
const internalErrorCode = -1
|
||||
|
||||
const (
|
||||
minikubeNotRunningStatusFlag = 1 << 0
|
||||
clusterNotRunningStatusFlag = 1 << 1
|
||||
k8sNotRunningStatusFlag = 1 << 2
|
||||
)
|
||||
|
||||
// statusCmd represents the status command
|
||||
var statusCmd = &cobra.Command{
|
||||
Use: "status",
|
||||
Short: "Gets the status of a local kubernetes cluster",
|
||||
Long: `Gets the status of a local kubernetes cluster.`,
|
||||
Long: `Gets the status of a local kubernetes cluster.
|
||||
Exit status contains the status of minikube's VM, cluster and kubernetes encoded on it's bits in this order from right to left.
|
||||
Eg: 7 meaning: 1 (for minikube NOK) + 2 (for cluster NOK) + 4 (for kubernetes NOK)`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var returnCode = 0
|
||||
api, err := machine.NewAPIClient()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err)
|
||||
os.Exit(1)
|
||||
os.Exit(internalErrorCode)
|
||||
}
|
||||
defer api.Close()
|
||||
|
||||
ms, err := cluster.GetHostStatus(api)
|
||||
if err != nil {
|
||||
glog.Errorln("Error getting machine status:", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||
}
|
||||
|
||||
cs := state.None.String()
|
||||
|
@ -67,29 +78,35 @@ var statusCmd = &cobra.Command{
|
|||
clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
|
||||
if err != nil {
|
||||
glog.Errorf("Error getting cluster bootstrapper: %s", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||
}
|
||||
cs, err = clusterBootstrapper.GetClusterStatus()
|
||||
if err != nil {
|
||||
glog.Errorln("Error cluster status:", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||
} else if cs != state.Running.String() {
|
||||
returnCode |= clusterNotRunningStatusFlag
|
||||
}
|
||||
|
||||
ip, err := cluster.GetHostDriverIP(api)
|
||||
if err != nil {
|
||||
glog.Errorln("Error host driver ip status:", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||
}
|
||||
kstatus, err := kubeconfig.GetKubeConfigStatus(ip, cmdUtil.GetKubeConfigPath(), config.GetMachineName())
|
||||
if err != nil {
|
||||
glog.Errorln("Error kubeconfig status:", err)
|
||||
cmdUtil.MaybeReportErrorAndExit(err)
|
||||
cmdUtil.MaybeReportErrorAndExitWithCode(err, internalErrorCode)
|
||||
}
|
||||
if kstatus {
|
||||
ks = "Correctly Configured: pointing to minikube-vm at " + ip.String()
|
||||
} else {
|
||||
ks = "Misconfigured: pointing to stale minikube-vm." +
|
||||
"\nTo fix the kubectl context, run minikube update-context"
|
||||
returnCode |= k8sNotRunningStatusFlag
|
||||
}
|
||||
} else {
|
||||
returnCode |= minikubeNotRunningStatusFlag
|
||||
}
|
||||
|
||||
status := Status{ms, cs, ks}
|
||||
|
@ -97,13 +114,15 @@ var statusCmd = &cobra.Command{
|
|||
tmpl, err := template.New("status").Parse(statusFormat)
|
||||
if err != nil {
|
||||
glog.Errorln("Error creating status template:", err)
|
||||
os.Exit(1)
|
||||
os.Exit(internalErrorCode)
|
||||
}
|
||||
err = tmpl.Execute(os.Stdout, status)
|
||||
if err != nil {
|
||||
glog.Errorln("Error executing status template:", err)
|
||||
os.Exit(1)
|
||||
os.Exit(internalErrorCode)
|
||||
}
|
||||
|
||||
os.Exit(returnCode)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,10 @@ func UploadError(b []byte, url string) error {
|
|||
}
|
||||
|
||||
func MaybeReportErrorAndExit(errToReport error) {
|
||||
MaybeReportErrorAndExitWithCode(errToReport, 1)
|
||||
}
|
||||
|
||||
func MaybeReportErrorAndExitWithCode(errToReport error, returnCode int) {
|
||||
var err error
|
||||
if viper.GetBool(config.WantReportError) {
|
||||
err = ReportError(errToReport, constants.ReportingURL)
|
||||
|
@ -146,7 +150,7 @@ To opt out of these messages, run the command:
|
|||
if err != nil {
|
||||
glog.Errorf(err.Error())
|
||||
}
|
||||
os.Exit(1)
|
||||
os.Exit(returnCode)
|
||||
}
|
||||
|
||||
func getInput(input chan string, r io.Reader) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
func TestStartStop(t *testing.T) {
|
||||
|
||||
runner := NewMinikubeRunner(t)
|
||||
runner.RunCommand("config set WantReportErrorPrompt false", true)
|
||||
runner.RunCommand("delete", false)
|
||||
runner.CheckStatus(state.None.String())
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error {
|
|||
}
|
||||
|
||||
func (m *MinikubeRunner) GetStatus() string {
|
||||
return m.RunCommand(fmt.Sprintf("status --format={{.MinikubeStatus}} %s", m.Args), true)
|
||||
return m.RunCommand(fmt.Sprintf("status --format={{.MinikubeStatus}} %s", m.Args), false)
|
||||
}
|
||||
|
||||
func (m *MinikubeRunner) GetLogs() string {
|
||||
|
|
Loading…
Reference in New Issue