Skip to content

Commit

Permalink
feat: unified minikube cluster status query
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Jun 1, 2024
1 parent 8754ae7 commit 4ed5406
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 534 deletions.
79 changes: 7 additions & 72 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (
"strconv"
"strings"

"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil/kverify"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/notify"
Expand All @@ -35,7 +34,6 @@ import (
"k8s.io/minikube/pkg/minikube/style"

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/state"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -115,77 +113,14 @@ func profileStatus(p *config.Profile, api libmachine.API) string {
if len(cps) == 0 {
exit.Message(reason.GuestCpConfig, "No control-plane nodes found.")
}

status := "Unknown"
healthyCPs := 0
for _, cp := range cps {
machineName := config.MachineName(*p.Config, cp)

ms, err := machine.Status(api, machineName)
if err != nil {
klog.Warningf("error loading profile (will continue): machine status for %s: %v", machineName, err)
continue
}
if ms != state.Running.String() {
klog.Warningf("error loading profile (will continue): machine %s is not running: %q", machineName, ms)
status = ms
continue
}

host, err := machine.LoadHost(api, machineName)
if err != nil {
klog.Warningf("error loading profile (will continue): load host for %s: %v", machineName, err)
continue
}

hs, err := host.Driver.GetState()
if err != nil {
klog.Warningf("error loading profile (will continue): host state for %s: %v", machineName, err)
continue
}
if hs != state.Running {
klog.Warningf("error loading profile (will continue): host %s is not running: %q", machineName, hs)
status = hs.String()
continue
}

cr, err := machine.CommandRunner(host)
if err != nil {
klog.Warningf("error loading profile (will continue): command runner for %s: %v", machineName, err)
continue
}

hostname, _, port, err := driver.ControlPlaneEndpoint(p.Config, &cp, host.DriverName)
if err != nil {
klog.Warningf("error loading profile (will continue): control-plane endpoint for %s: %v", machineName, err)
continue
}

as, err := kverify.APIServerStatus(cr, hostname, port)
if err != nil {
klog.Warningf("error loading profile (will continue): apiserver status for %s: %v", machineName, err)
continue
}
status = as.String()
if as != state.Running {
klog.Warningf("error loading profile (will continue): apiserver %s is not running: %q", machineName, hs)
continue
}

healthyCPs++
statuses, err := cluster.GetStatus(api, p.Config)
if err != nil {
klog.Errorf("error getting statuses: %v", err)
return "Unknown"
}
clusterStatus := cluster.GetClusterState(statuses, ClusterFlagValue(), p.Config)

if config.IsHA(*p.Config) {
switch {
case healthyCPs < 2:
return state.Stopped.String()
case healthyCPs == 2:
return "Degraded"
default:
return "HAppy"
}
}
return status
return clusterStatus.StatusName
}

func renderProfilesTable(ps [][]string) {
Expand Down
Loading

0 comments on commit 4ed5406

Please sign in to comment.