Skip to content

Commit

Permalink
Change default status output to not include the ip. Simplify json output
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Woodcock committed Oct 16, 2019
1 parent d33f3b2 commit a34b498
Showing 1 changed file with 18 additions and 35 deletions.
53 changes: 18 additions & 35 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ import (
var statusFormat string
var output string

type KubeconfigStatus struct {
Correct bool
IP string
var KubeconfigStatus = struct {
Configured string
Misconfigured string
}{
Configured: `Configured`,
Misconfigured: `Misconfigured`,
}

// Status represents the status
type Status struct {
Host string
Kubelet string
APIServer string
Kubeconfig string
KubeconfigStatus KubeconfigStatus
Host string
Kubelet string
APIServer string
Kubeconfig string
}

const (
Expand All @@ -61,7 +63,7 @@ const (
defaultStatusFormat = `host: {{.Host}}
kubelet: {{.Kubelet}}
apiserver: {{.APIServer}}
kubectl: {{.Kubeconfig}}
kubeconfig: {{.Kubeconfig}}
`
)

Expand Down Expand Up @@ -93,8 +95,6 @@ var statusCmd = &cobra.Command{
kubeletSt := state.None.String()
kubeconfigSt := state.None.String()
apiserverSt := state.None.String()
var ks bool
var ipString = ""

if hostSt == state.Running.String() {
clusterBootstrapper, err := getClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
Expand Down Expand Up @@ -127,16 +127,14 @@ var statusCmd = &cobra.Command{
returnCode |= clusterNotRunningStatusFlag
}

ks, err = kubeconfig.IsClusterInConfig(ip, config.GetMachineName())
ks, err := kubeconfig.IsClusterInConfig(ip, config.GetMachineName())
if err != nil {
glog.Errorln("Error kubeconfig status:", err)
}
if ks {
kubeconfigSt = "Correctly Configured: pointing to minikube-vm at " + ip.String()
ipString = ip.String()
kubeconfigSt = KubeconfigStatus.Configured
} else {
kubeconfigSt = "Misconfigured: pointing to stale minikube-vm." +
"\nTo fix the kubectl context, run minikube update-context"
kubeconfigSt = KubeconfigStatus.Misconfigured
returnCode |= k8sNotRunningStatusFlag
}
} else {
Expand All @@ -148,10 +146,6 @@ var statusCmd = &cobra.Command{
Kubelet: kubeletSt,
APIServer: apiserverSt,
Kubeconfig: kubeconfigSt,
KubeconfigStatus: KubeconfigStatus{
Correct: ks,
IP: ipString,
},
}

switch strings.ToLower(output) {
Expand Down Expand Up @@ -184,25 +178,14 @@ var printStatusText = func(status Status) {
if err != nil {
exit.WithError("Error executing status template", err)
}
if status.Kubeconfig == KubeconfigStatus.Misconfigured {
out.WarningT("Warning: Your kubectl is pointing to stale minikube-vm.\nTo fix the kubectl context, run `minikube update-context`")
}
}

var printStatusJSON = func(status Status) {

var kubeConfigStatus interface{}
if status.Kubeconfig != state.None.String() {
kubeConfigStatus = status.KubeconfigStatus
} else {
kubeConfigStatus = nil
}

var outputObject = map[string]interface{}{
"Host": status.Host,
"Kubelet": status.Kubelet,
"APIServer": status.APIServer,
"Kubeconfig": kubeConfigStatus,
}

jsonString, err := json.Marshal(outputObject)
jsonString, err := json.Marshal(status)
if err != nil {
exit.WithError("Error converting status to json", err)
}
Expand Down

0 comments on commit a34b498

Please sign in to comment.