未验证 提交 aae77843 编写于 作者: P priyawadhwa 提交者: GitHub

Merge pull request #9383 from priyawadhwa/status-bg

Fix minikube status bug when cluster is paused
......@@ -96,6 +96,11 @@ const (
)
var (
exitCodeToHTTPCode = map[int]int{
// exit code 26 corresponds to insufficient storage
26: 507,
}
codeNames = map[int]string{
100: "Starting",
101: "Pausing",
......@@ -448,14 +453,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],
},
......@@ -539,6 +548,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
......
......@@ -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)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册