未验证 提交 fe5f5d99 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #10906 from tharun208/feat/not_mention_timeToStop

status: Omit `timeToStop` if nonexistent
......@@ -136,7 +136,7 @@ type Status struct {
APIServer string
Kubeconfig string
Worker bool
TimeToStop string
TimeToStop string `json:",omitempty"`
DockerEnv string `json:",omitempty"`
PodManEnv string `json:",omitempty"`
}
......@@ -146,7 +146,7 @@ type ClusterState struct {
BaseState
BinaryVersion string
TimeToStop string
TimeToStop string `json:",omitempty"`
Components map[string]BaseState
Nodes []NodeState
}
......@@ -185,7 +185,9 @@ host: {{.Host}}
kubelet: {{.Kubelet}}
apiserver: {{.APIServer}}
kubeconfig: {{.Kubeconfig}}
{{- if .TimeToStop }}
timeToStop: {{.TimeToStop}}
{{- end }}
{{- if .DockerEnv }}
docker-env: {{.DockerEnv}}
{{- end }}
......@@ -319,7 +321,6 @@ func nodeStatus(api libmachine.API, cc config.ClusterConfig, n config.Node) (*St
Kubelet: Nonexistent,
Kubeconfig: Nonexistent,
Worker: !controlPlane,
TimeToStop: Nonexistent,
}
hs, err := machine.Status(api, name)
......
......@@ -56,13 +56,13 @@ func TestStatusText(t *testing.T) {
},
{
name: "paused",
state: &Status{Name: "minikube", Host: "Running", Kubelet: "Stopped", APIServer: "Paused", Kubeconfig: Configured, TimeToStop: Nonexistent},
want: "minikube\ntype: Control Plane\nhost: Running\nkubelet: Stopped\napiserver: Paused\nkubeconfig: Configured\ntimeToStop: Nonexistent\n\n",
state: &Status{Name: "minikube", Host: "Running", Kubelet: "Stopped", APIServer: "Paused", Kubeconfig: Configured},
want: "minikube\ntype: Control Plane\nhost: Running\nkubelet: Stopped\napiserver: Paused\nkubeconfig: Configured\n\n",
},
{
name: "down",
state: &Status{Name: "minikube", Host: "Stopped", Kubelet: "Stopped", APIServer: "Stopped", Kubeconfig: Misconfigured, TimeToStop: Nonexistent},
want: "minikube\ntype: Control Plane\nhost: Stopped\nkubelet: Stopped\napiserver: Stopped\nkubeconfig: Misconfigured\ntimeToStop: Nonexistent\n\n\nWARNING: Your kubectl is pointing to stale minikube-vm.\nTo fix the kubectl context, run `minikube update-context`\n",
state: &Status{Name: "minikube", Host: "Stopped", Kubelet: "Stopped", APIServer: "Stopped", Kubeconfig: Misconfigured},
want: "minikube\ntype: Control Plane\nhost: Stopped\nkubelet: Stopped\napiserver: Stopped\nkubeconfig: Misconfigured\n\n\nWARNING: Your kubectl is pointing to stale minikube-vm.\nTo fix the kubectl context, run `minikube update-context`\n",
},
}
for _, tc := range tests {
......@@ -87,8 +87,8 @@ func TestStatusJSON(t *testing.T) {
state *Status
}{
{"ok", &Status{Host: "Running", Kubelet: "Running", APIServer: "Running", Kubeconfig: Configured, TimeToStop: "10m"}},
{"paused", &Status{Host: "Running", Kubelet: "Stopped", APIServer: "Paused", Kubeconfig: Configured, TimeToStop: Nonexistent}},
{"down", &Status{Host: "Stopped", Kubelet: "Stopped", APIServer: "Stopped", Kubeconfig: Misconfigured, TimeToStop: Nonexistent}},
{"paused", &Status{Host: "Running", Kubelet: "Stopped", APIServer: "Paused", Kubeconfig: Configured}},
{"down", &Status{Host: "Stopped", Kubelet: "Stopped", APIServer: "Stopped", Kubeconfig: Misconfigured}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
......
......@@ -23,7 +23,7 @@ minikube status [flags]
```
-f, --format string Go template format string for the status output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
For the list accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd#Status (default "{{.Name}}\ntype: Control Plane\nhost: {{.Host}}\nkubelet: {{.Kubelet}}\napiserver: {{.APIServer}}\nkubeconfig: {{.Kubeconfig}}\ntimeToStop: {{.TimeToStop}}\n{{- if .DockerEnv }}\ndocker-env: {{.DockerEnv}}\n{{- end }}\n{{- if .PodManEnv }}\npodman-env: {{.PodManEnv}}\n{{- end }}\n\n")
For the list accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd#Status (default "{{.Name}}\ntype: Control Plane\nhost: {{.Host}}\nkubelet: {{.Kubelet}}\napiserver: {{.APIServer}}\nkubeconfig: {{.Kubeconfig}}\n{{- if .TimeToStop }}\ntimeToStop: {{.TimeToStop}}\n{{- end }}\n{{- if .DockerEnv }}\ndocker-env: {{.DockerEnv}}\n{{- end }}\n{{- if .PodManEnv }}\npodman-env: {{.PodManEnv}}\n{{- end }}\n\n")
-l, --layout string output layout (EXPERIMENTAL, JSON only): 'nodes' or 'cluster' (default "nodes")
-n, --node string The node to check status for. Defaults to control plane. Leave blank with default format for status on all nodes.
-o, --output string minikube status --output OUTPUT. json, text (default "text")
......
......@@ -67,10 +67,10 @@ func TestScheduledStopWindows(t *testing.T) {
// sleep for 5 seconds
time.Sleep(5 * time.Second)
// make sure minikube timetoStop is not present
ensureTimeToStopNotPresent(ctx, t, profile)
// make sure minikube status is "Stopped"
ensureMinikubeStatus(ctx, t, profile, "Host", state.Stopped.String())
// make sure minikube timtostop is "Nonexistent"
ensureMinikubeStatus(ctx, t, profile, "TimeToStop", "Nonexistent")
}
func TestScheduledStopUnix(t *testing.T) {
......@@ -113,10 +113,10 @@ func TestScheduledStopUnix(t *testing.T) {
t.Fatalf("process %v running but should have been killed on reschedule of stop", pid)
}
// make sure minikube timetoStop is not present
ensureTimeToStopNotPresent(ctx, t, profile)
// make sure minikube status is "Stopped"
ensureMinikubeStatus(ctx, t, profile, "Host", state.Stopped.String())
// make sure minikube timtostop is "Nonexistent"
ensureMinikubeStatus(ctx, t, profile, "TimeToStop", "Nonexistent")
}
func startMinikube(ctx context.Context, t *testing.T, profile string) {
......@@ -195,3 +195,14 @@ func ensureMinikubeScheduledTime(ctx context.Context, t *testing.T, profile stri
t.Fatalf("error %v", err)
}
}
func ensureTimeToStopNotPresent(ctx context.Context, t *testing.T, profile string) {
args := []string{"status", "-p", profile}
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("minikube status: %v\n%s", err, rr.Output())
}
if strings.Contains(rr.Output(), "TimeToStop") {
t.Fatalf("expected status output to not include `TimeToStop` but got *%s*", rr.Output())
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册