Skip to content

Commit d40751f

Browse files
committed
Fix nonexistent profile
1 parent 4e3b9c8 commit d40751f

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

cmd/minikube/cmd/dashboard.go

+25-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,28 @@ var dashboardCmd = &cobra.Command{
7971
if err != nil {
8072
exit.WithError("Error getting client", err)
8173
}
74+
75+
_, err = api.Load(pkg_config.GetMachineName())
76+
if err != nil {
77+
switch err := errors.Cause(err).(type) {
78+
case mcnerror.ErrHostDoesNotExist:
79+
console.OutStyle(console.Meh, "%q cluster does not exist", pkg_config.GetMachineName())
80+
os.Exit(0)
81+
default:
82+
exit.WithError("Error getting cluster", err)
83+
}
84+
}
85+
86+
err = proxy.ExcludeIP(cc.KubernetesConfig.NodeIP) // to be used for http get calls
87+
if err != nil {
88+
glog.Errorf("Error excluding IP from proxy: %s", err)
89+
}
90+
91+
kubectl, err := exec.LookPath("kubectl")
92+
if err != nil {
93+
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/")
94+
}
95+
8296
cluster.EnsureMinikubeRunningOrExit(api, 1)
8397

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

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

134148
stdoutPipe, err := cmd.StdoutPipe()
135149
if err != nil {

0 commit comments

Comments
 (0)