Skip to content

Commit

Permalink
Update pkg/minikube/cluster/status.go
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Powell <44844360+spowelljr@users.noreply.github.com>
  • Loading branch information
ComradeProgrammer and spowelljr committed Jun 29, 2024
1 parent 06b019f commit e39e84c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func profileStatus(p *config.Profile, api libmachine.API) string {
klog.Errorf("error getting statuses: %v", err)
return "Unknown"
}
clusterStatus := cluster.GetClusterState(statuses, ClusterFlagValue(), p.Config)
clusterStatus := cluster.GetState(statuses, ClusterFlagValue(), p.Config)

return clusterStatus.StatusName
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func statusJSON(st []*cluster.Status, w io.Writer) error {
}

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

bs, err := json.Marshal(cs)
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions pkg/minikube/cluster/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ type Status struct {
PodManEnv string `json:",omitempty"`
}

// ClusterState holds a cluster state representation
// State holds a cluster state representation
//
//nolint:revive
type ClusterState struct {
type State struct {
BaseState

BinaryVersion string
Expand Down Expand Up @@ -166,6 +166,7 @@ type BaseState struct {
StepDetail string `json:",omitempty"`
}

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

// clusterState converts Status structs into a ClusterState struct
// GetState converts Status structs into a State struct
//
//nolint:gocyclo
func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) ClusterState {
statusName := sts[0].APIServer
if sts[0].Host == codeNames[InsufficientStorage] {
statusName = sts[0].Host
func GetState(sts []*Status, profile string, cc *config.ClusterConfig) State {
statusName := ""
if len(sts) > 0 {
statusName = sts[0].APIServer
if sts[0].Host == codeNames[InsufficientStorage] {
statusName = sts[0].Host
}
}
sc := statusCode(statusName)

cs := ClusterState{
cs := State{
BinaryVersion: version.GetVersion(),

BaseState: BaseState{
Expand Down Expand Up @@ -344,7 +348,7 @@ func GetClusterState(sts []*Status, profile string, cc *config.ClusterConfig) Cl
return cs
}

// nodeStatus looks up the status of a node
// NodeStatus looks up the status of a node
func NodeStatus(api libmachine.API, cc config.ClusterConfig, n config.Node) (*Status, error) {
controlPlane := n.ControlPlane
name := config.MachineName(cc, n)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func validateStatus(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)

statusOutput := runStatusCmd(ctx, t, profile, false)
var cs cluster.ClusterState
var cs cluster.State
if err := json.Unmarshal(statusOutput, &cs); err != nil {
t.Fatalf("unmarshalling: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func runStatusCmd(ctx context.Context, t *testing.T, profile string, increaseEnv
}

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

0 comments on commit e39e84c

Please sign in to comment.