Skip to content

Commit e8d3a51

Browse files
Update pkg/minikube/cluster/status.go
Co-authored-by: Steven Powell <[email protected]>
1 parent 06b019f commit e8d3a51

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

cmd/minikube/cmd/config/profile_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func profileStatus(p *config.Profile, api libmachine.API) string {
118118
klog.Errorf("error getting statuses: %v", err)
119119
return "Unknown"
120120
}
121-
clusterStatus := cluster.GetClusterState(statuses, ClusterFlagValue(), p.Config)
121+
clusterStatus := cluster.GetState(statuses, ClusterFlagValue(), p.Config)
122122

123123
return clusterStatus.StatusName
124124
}

cmd/minikube/cmd/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func statusJSON(st []*cluster.Status, w io.Writer) error {
233233
}
234234

235235
func clusterStatusJSON(statuses []*cluster.Status, w io.Writer, cc *config.ClusterConfig) error {
236-
cs := cluster.GetClusterState(statuses, ClusterFlagValue(), cc)
236+
cs := cluster.GetState(statuses, ClusterFlagValue(), cc)
237237

238238
bs, err := json.Marshal(cs)
239239
if err != nil {

pkg/minikube/cluster/status.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ type Status struct {
130130
PodManEnv string `json:",omitempty"`
131131
}
132132

133-
// ClusterState holds a cluster state representation
133+
// State holds a cluster state representation
134134
//
135135
//nolint:revive
136-
type ClusterState struct {
136+
type State struct {
137137
BaseState
138138

139139
BinaryVersion string
@@ -166,6 +166,7 @@ type BaseState struct {
166166
StepDetail string `json:",omitempty"`
167167
}
168168

169+
// GetStatus returns the statuses of each node
169170
func GetStatus(api libmachine.API, cc *config.ClusterConfig) ([]*Status, error) {
170171
var statuses []*Status
171172
for _, n := range cc.Nodes {
@@ -188,17 +189,20 @@ func GetStatus(api libmachine.API, cc *config.ClusterConfig) ([]*Status, error)
188189
return statuses, nil
189190
}
190191

191-
// clusterState converts Status structs into a ClusterState struct
192+
// GetState converts Status structs into a State struct
192193
//
193194
//nolint:gocyclo
194-
func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) ClusterState {
195-
statusName := sts[0].APIServer
196-
if sts[0].Host == codeNames[InsufficientStorage] {
197-
statusName = sts[0].Host
195+
func GetState(sts []*Status, profile string, cc *config.ClusterConfig) State {
196+
statusName := ""
197+
if len(sts) > 0 {
198+
statusName = sts[0].APIServer
199+
if sts[0].Host == codeNames[InsufficientStorage] {
200+
statusName = sts[0].Host
201+
}
198202
}
199203
sc := statusCode(statusName)
200204

201-
cs := ClusterState{
205+
cs := State{
202206
BinaryVersion: version.GetVersion(),
203207

204208
BaseState: BaseState{
@@ -260,7 +264,6 @@ func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) Cl
260264
var finalStep map[string]string
261265

262266
for _, ev := range evs {
263-
// klog.Infof("read event: %+v", ev)
264267
if ev.Type() == "io.k8s.sigs.minikube.step" {
265268
var data map[string]string
266269
err := ev.DataAs(&data)
@@ -326,7 +329,6 @@ func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) Cl
326329
}
327330
}
328331

329-
// if it is
330332
if config.IsHA(*cc) && started {
331333
switch {
332334
case healthyCPs < 2:
@@ -344,7 +346,7 @@ func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) Cl
344346
return cs
345347
}
346348

347-
// nodeStatus looks up the status of a node
349+
// NodeStatus looks up the status of a node
348350
func NodeStatus(api libmachine.API, cc config.ClusterConfig, n config.Node) (*Status, error) {
349351
controlPlane := n.ControlPlane
350352
name := config.MachineName(cc, n)

test/integration/pause_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func validateStatus(ctx context.Context, t *testing.T, profile string) {
191191
defer PostMortemLogs(t, profile)
192192

193193
statusOutput := runStatusCmd(ctx, t, profile, false)
194-
var cs cluster.ClusterState
194+
var cs cluster.State
195195
if err := json.Unmarshal(statusOutput, &cs); err != nil {
196196
t.Fatalf("unmarshalling: %v", err)
197197
}

test/integration/status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func runStatusCmd(ctx context.Context, t *testing.T, profile string, increaseEnv
8282
}
8383

8484
func verifyClusterState(t *testing.T, contents []byte) {
85-
var cs cluster.ClusterState
85+
var cs cluster.State
8686
if err := json.Unmarshal(contents, &cs); err != nil {
8787
t.Fatalf("unmarshalling: %v", err)
8888
}

0 commit comments

Comments
 (0)