Skip to content

Commit c38897d

Browse files
unified minikube cluster status query (#18998)
* feat: unified minikube cluster status query * Update pkg/minikube/cluster/status.go Co-authored-by: Steven Powell <[email protected]> * Update pkg/minikube/cluster/status.go Co-authored-by: Steven Powell <[email protected]> * Update pkg/minikube/cluster/status.go Co-authored-by: Steven Powell <[email protected]> --------- Co-authored-by: Steven Powell <[email protected]>
1 parent 025b327 commit c38897d

File tree

8 files changed

+564
-549
lines changed

8 files changed

+564
-549
lines changed

Diff for: cmd/minikube/cmd/config/profile_list.go

+7-72
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
"strconv"
2424
"strings"
2525

26-
"k8s.io/minikube/pkg/minikube/bootstrapper/bsutil/kverify"
26+
"k8s.io/minikube/pkg/minikube/cluster"
2727
"k8s.io/minikube/pkg/minikube/config"
2828
"k8s.io/minikube/pkg/minikube/constants"
29-
"k8s.io/minikube/pkg/minikube/driver"
3029
"k8s.io/minikube/pkg/minikube/exit"
3130
"k8s.io/minikube/pkg/minikube/machine"
3231
"k8s.io/minikube/pkg/minikube/notify"
@@ -35,7 +34,6 @@ import (
3534
"k8s.io/minikube/pkg/minikube/style"
3635

3736
"github.com/docker/machine/libmachine"
38-
"github.com/docker/machine/libmachine/state"
3937
"github.com/olekukonko/tablewriter"
4038
"github.com/spf13/cobra"
4139

@@ -115,77 +113,14 @@ func profileStatus(p *config.Profile, api libmachine.API) string {
115113
if len(cps) == 0 {
116114
exit.Message(reason.GuestCpConfig, "No control-plane nodes found.")
117115
}
118-
119-
status := "Unknown"
120-
healthyCPs := 0
121-
for _, cp := range cps {
122-
machineName := config.MachineName(*p.Config, cp)
123-
124-
ms, err := machine.Status(api, machineName)
125-
if err != nil {
126-
klog.Warningf("error loading profile (will continue): machine status for %s: %v", machineName, err)
127-
continue
128-
}
129-
if ms != state.Running.String() {
130-
klog.Warningf("error loading profile (will continue): machine %s is not running: %q", machineName, ms)
131-
status = ms
132-
continue
133-
}
134-
135-
host, err := machine.LoadHost(api, machineName)
136-
if err != nil {
137-
klog.Warningf("error loading profile (will continue): load host for %s: %v", machineName, err)
138-
continue
139-
}
140-
141-
hs, err := host.Driver.GetState()
142-
if err != nil {
143-
klog.Warningf("error loading profile (will continue): host state for %s: %v", machineName, err)
144-
continue
145-
}
146-
if hs != state.Running {
147-
klog.Warningf("error loading profile (will continue): host %s is not running: %q", machineName, hs)
148-
status = hs.String()
149-
continue
150-
}
151-
152-
cr, err := machine.CommandRunner(host)
153-
if err != nil {
154-
klog.Warningf("error loading profile (will continue): command runner for %s: %v", machineName, err)
155-
continue
156-
}
157-
158-
hostname, _, port, err := driver.ControlPlaneEndpoint(p.Config, &cp, host.DriverName)
159-
if err != nil {
160-
klog.Warningf("error loading profile (will continue): control-plane endpoint for %s: %v", machineName, err)
161-
continue
162-
}
163-
164-
as, err := kverify.APIServerStatus(cr, hostname, port)
165-
if err != nil {
166-
klog.Warningf("error loading profile (will continue): apiserver status for %s: %v", machineName, err)
167-
continue
168-
}
169-
status = as.String()
170-
if as != state.Running {
171-
klog.Warningf("error loading profile (will continue): apiserver %s is not running: %q", machineName, hs)
172-
continue
173-
}
174-
175-
healthyCPs++
116+
statuses, err := cluster.GetStatus(api, p.Config)
117+
if err != nil {
118+
klog.Errorf("error getting statuses: %v", err)
119+
return "Unknown"
176120
}
121+
clusterStatus := cluster.GetState(statuses, ClusterFlagValue(), p.Config)
177122

178-
if config.IsHA(*p.Config) {
179-
switch {
180-
case healthyCPs < 2:
181-
return state.Stopped.String()
182-
case healthyCPs == 2:
183-
return "Degraded"
184-
default:
185-
return "HAppy"
186-
}
187-
}
188-
return status
123+
return clusterStatus.StatusName
189124
}
190125

191126
func renderProfilesTable(ps [][]string) {

0 commit comments

Comments
 (0)