Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minikube status bug when cluster is paused #9383

Merged
merged 5 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ const (
)

var (
exitCodeToHTTPCode = map[int]int{
// exit code 26 corresponds to insufficient storage
26: 507,
}

codeNames = map[int]string{
100: "Starting",
101: "Pausing",
Expand Down Expand Up @@ -442,14 +447,18 @@ func readEventLog(name string) ([]cloudevents.Event, time.Time, error) {

// clusterState converts Status structs into a ClusterState struct
func clusterState(sts []*Status) ClusterState {
sc := statusCode(sts[0].Host)
statusName := sts[0].APIServer
if sts[0].Host == codeNames[InsufficientStorage] {
statusName = sts[0].Host
}
sc := statusCode(statusName)
cs := ClusterState{
BinaryVersion: version.GetVersion(),

BaseState: BaseState{
Name: ClusterFlagValue(),
StatusCode: sc,
StatusName: sts[0].Host,
StatusName: statusName,
StatusDetail: codeDetails[sc],
},

Expand Down Expand Up @@ -533,6 +542,9 @@ func clusterState(sts []*Status) ClusterState {
glog.Errorf("unable to convert exit code to int: %v", err)
continue
}
if val, ok := exitCodeToHTTPCode[exitCode]; ok {
exitCode = val
}
transientCode = exitCode
for _, n := range cs.Nodes {
n.StatusCode = transientCode
Expand Down
48 changes: 44 additions & 4 deletions test/integration/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,26 @@ func TestInsufficientStorage(t *testing.T) {
}

// make sure 'minikube status' has correct output
stdout := runStatusCmd(ctx, t, profile)
stdout := runStatusCmd(ctx, t, profile, true)
verifyClusterState(t, stdout)

// try deleting events.json and make sure this still works
eventsFile := path.Join(localpath.MiniPath(), "profiles", profile, "events.json")
if err := os.Remove(eventsFile); err != nil {
t.Fatalf("removing %s", eventsFile)
}
stdout = runStatusCmd(ctx, t, profile)
stdout = runStatusCmd(ctx, t, profile, true)
verifyClusterState(t, stdout)
}

// runStatusCmd runs the status command and returns stdout
func runStatusCmd(ctx context.Context, t *testing.T, profile string) []byte {
func runStatusCmd(ctx context.Context, t *testing.T, profile string, increaseEnv bool) []byte {
// make sure minikube status shows insufficient storage
c := exec.CommandContext(ctx, Target(), "status", "-p", profile, "--output=json", "--layout=cluster")
// artificially set /var to 100% capacity
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestDiskUsedEnv))
if increaseEnv {
c.Env = append(os.Environ(), fmt.Sprintf("%s=100", constants.TestDiskUsedEnv))
}
rr, err := Run(t, c)
// status exits non-0 if status isn't Running
if err == nil {
Expand All @@ -96,3 +98,41 @@ func verifyClusterState(t *testing.T, contents []byte) {
}
}
}

func TestPauseStatus(t *testing.T) {
// run start
profile := UniqueProfileName("pause-status")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5))
defer Cleanup(t, profile, cancel)

startArgs := []string{"start", "-p", profile, "--output=json", "--wait=true"}
startArgs = append(startArgs, StartArgs()...)
c := exec.CommandContext(ctx, Target(), startArgs...)

rr, err := Run(t, c)
if err != nil {
t.Fatalf("minikube start failed %v\n%v", rr.Command(), err)
}

// run pause
pauseArgs := []string{"pause", "-p", profile}
c = exec.CommandContext(ctx, Target(), pauseArgs...)
rr, err = Run(t, c)
if err != nil {
t.Fatalf("minikube pause failed %v\n%v", rr.Command(), err)
}

// run status
statusOutput := runStatusCmd(context.Background(), t, profile, false)
var cs cmd.ClusterState
if err := json.Unmarshal(statusOutput, &cs); err != nil {
t.Fatalf("unmarshalling: %v", err)
}
// verify the status looks as we expect
if cs.StatusCode != cmd.Paused {
t.Fatalf("incorrect status code: %v", cs.StatusCode)
}
if cs.StatusName != "Paused" {
t.Fatalf("incorrect status name: %v", cs.StatusName)
}
}