From a05dc6516ba2c65d3267f5c4237b36e8f6445d3d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 29 Sep 2020 16:56:15 -0400 Subject: [PATCH 1/5] Revert bug in `minikube status` When the cluster is Paused, `minikube status` currently says that it is `Running`. Reverting a change I made in a previous PR to take the status of the apiserver should fix this. --- cmd/minikube/cmd/status.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index df7184c0c1cb..6dfd417cd3cb 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -442,14 +442,14 @@ 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) + sc := statusCode(sts[0].APIServer) cs := ClusterState{ BinaryVersion: version.GetVersion(), BaseState: BaseState{ Name: ClusterFlagValue(), StatusCode: sc, - StatusName: sts[0].Host, + StatusName: sts[0].APIServer, StatusDetail: codeDetails[sc], }, From 6e91d719dd194b51c1e9fc162fc95ee440db26f0 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 29 Sep 2020 19:38:12 -0400 Subject: [PATCH 2/5] Revert status code cmd --- cmd/minikube/cmd/status.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index 6dfd417cd3cb..f57bc0e831b7 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -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 @@ -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 - 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", @@ -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", } ) From 7046998831093cd0580ba5163f40dcddc8f713fd Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 2 Oct 2020 17:48:52 -0400 Subject: [PATCH 3/5] If insufficient storage is the issue, then show that in status --- cmd/minikube/cmd/status.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index f57bc0e831b7..64f057d28298 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -443,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].APIServer) + 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].APIServer, + StatusName: statusName, StatusDetail: codeDetails[sc], }, From 4f7d9006d0c20ff82857c2479a31830f5b095ea3 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 2 Oct 2020 18:04:46 -0400 Subject: [PATCH 4/5] Add integration test --- test/integration/status_test.go | 48 ++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/test/integration/status_test.go b/test/integration/status_test.go index 15b8a702f899..9980d0a4c6b1 100644 --- a/test/integration/status_test.go +++ b/test/integration/status_test.go @@ -52,7 +52,7 @@ 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 @@ -60,16 +60,18 @@ func TestInsufficientStorage(t *testing.T) { 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 { @@ -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) + } +} From 7d62ce1c1c4ce3341f21b23f1134ed3b43b2adbe Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Sat, 3 Oct 2020 15:29:15 -0400 Subject: [PATCH 5/5] convert from exit codes to http codes if appropriate --- cmd/minikube/cmd/status.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index 64f057d28298..b428bbc3f56e 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -66,8 +66,6 @@ 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 @@ -86,18 +84,23 @@ const ( Paused = 418 // I'm a teapot! // 5xx signifies a server-side error (that may be retryable) - Error = 500 - Unknown = 520 + Error = 500 + InsufficientStorage = 507 + Unknown = 520 ) var ( + exitCodeToHTTPCode = map[int]int{ + // exit code 26 corresponds to insufficient storage + 26: 507, + } + codeNames = map[int]string{ - reason.ExInsufficientStorage: "InsufficientStorage", - 100: "Starting", - 101: "Pausing", - 102: "Unpausing", - 110: "Stopping", - 103: "Deleting", + 100: "Starting", + 101: "Pausing", + 102: "Unpausing", + 110: "Stopping", + 103: "Deleting", 200: "OK", 203: "Warning", @@ -107,11 +110,12 @@ var ( 418: "Paused", 500: "Error", + 507: "InsufficientStorage", 520: "Unknown", } codeDetails = map[int]string{ - reason.ExInsufficientStorage: "/var is almost out of disk space", + 507: "/var is almost out of disk space", } ) @@ -538,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