Skip to content

Commit 6aa51c1

Browse files
Merge pull request #4396 from fenglixa/fix-dashboard-nonexistent
dashboard: detect nonexistent profile instead of causing a panic
2 parents 27d56c1 + bbc679b commit 6aa51c1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

cmd/minikube/cmd/dashboard.go

+24-11
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626
"regexp"
2727
"time"
2828

29+
"github.com/docker/machine/libmachine/mcnerror"
2930
"github.com/golang/glog"
3031
"github.com/pkg/browser"
3132
"github.com/pkg/errors"
3233
"github.com/spf13/cobra"
3334
configcmd "k8s.io/minikube/cmd/minikube/cmd/config"
3435
"k8s.io/minikube/pkg/minikube/cluster"
35-
"k8s.io/minikube/pkg/minikube/config"
3636
pkg_config "k8s.io/minikube/pkg/minikube/config"
3737
"k8s.io/minikube/pkg/minikube/console"
3838
"k8s.io/minikube/pkg/minikube/exit"
@@ -59,15 +59,7 @@ var dashboardCmd = &cobra.Command{
5959
if err != nil && !os.IsNotExist(err) {
6060
console.ErrLn("Error loading profile config: %v", err)
6161
}
62-
err = proxy.ExcludeIP(cc.KubernetesConfig.NodeIP) // to be used for http get calls
63-
if err != nil {
64-
glog.Errorf("Error excluding IP from proxy: %s", err)
65-
}
6662

67-
kubectl, err := exec.LookPath("kubectl")
68-
if err != nil {
69-
exit.WithCode(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
70-
}
7163
api, err := machine.NewAPIClient()
7264
defer func() {
7365
err := api.Close()
@@ -79,6 +71,27 @@ var dashboardCmd = &cobra.Command{
7971
if err != nil {
8072
exit.WithError("Error getting client", err)
8173
}
74+
75+
if _, err = api.Load(pkg_config.GetMachineName()); err != nil {
76+
switch err := errors.Cause(err).(type) {
77+
case mcnerror.ErrHostDoesNotExist:
78+
console.OutStyle(console.Meh, "%q cluster does not exist", pkg_config.GetMachineName())
79+
os.Exit(exit.Unavailable)
80+
default:
81+
exit.WithError("Error getting cluster", err)
82+
}
83+
}
84+
85+
err = proxy.ExcludeIP(cc.KubernetesConfig.NodeIP) // to be used for http get calls
86+
if err != nil {
87+
glog.Errorf("Error excluding IP from proxy: %s", err)
88+
}
89+
90+
kubectl, err := exec.LookPath("kubectl")
91+
if err != nil {
92+
exit.WithCode(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
93+
}
94+
8295
cluster.EnsureMinikubeRunningOrExit(api, 1)
8396

8497
// Send status messages to stderr for folks re-using this output.
@@ -127,9 +140,9 @@ var dashboardCmd = &cobra.Command{
127140
// kubectlProxy runs "kubectl proxy", returning host:port
128141
func kubectlProxy(path string) (*exec.Cmd, string, error) {
129142
// port=0 picks a random system port
130-
// config.GetMachineName() respects the -p (profile) flag
143+
// pkg_config.GetMachineName() respects the -p (profile) flag
131144

132-
cmd := exec.Command(path, "--context", config.GetMachineName(), "proxy", "--port=0")
145+
cmd := exec.Command(path, "--context", pkg_config.GetMachineName(), "proxy", "--port=0")
133146

134147
stdoutPipe, err := cmd.StdoutPipe()
135148
if err != nil {

0 commit comments

Comments
 (0)