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 4 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
29 changes: 17 additions & 12 deletions cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
// Irrelevant is used for statuses that aren't meaningful for worker nodes
Irrelevant = "Irrelevant"

InsufficientStorage = reason.ExInsufficientStorage

// New status modes, based roughly on HTTP/SMTP standards
// 1xx signifies a transitional state. If retried, it will soon return a 2xx, 4xx, or 5xx
Starting = 100
Expand All @@ -84,18 +86,18 @@ const (
Paused = 418 // I'm a teapot!

// 5xx signifies a server-side error (that may be retryable)
Error = 500
InsufficientStorage = 507
priyawadhwa marked this conversation as resolved.
Show resolved Hide resolved
Unknown = 520
Error = 500
Unknown = 520
)

var (
codeNames = map[int]string{
100: "Starting",
101: "Pausing",
102: "Unpausing",
110: "Stopping",
103: "Deleting",
reason.ExInsufficientStorage: "InsufficientStorage",
100: "Starting",
101: "Pausing",
102: "Unpausing",
110: "Stopping",
103: "Deleting",

200: "OK",
203: "Warning",
Expand All @@ -105,12 +107,11 @@ var (
418: "Paused",

500: "Error",
507: "InsufficientStorage",
520: "Unknown",
}

codeDetails = map[int]string{
507: "/var is almost out of disk space",
reason.ExInsufficientStorage: "/var is almost out of disk space",
}
)

Expand Down Expand Up @@ -442,14 +443,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
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)
}
}