Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run dashboard with internal kubectl if not in path #7299

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ var dashboardCmd = &cobra.Command{
}
}

kubectl, err := exec.LookPath("kubectl")
if err != nil {
exit.WithCodeT(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
}
kubectlVersion := co.Config.KubernetesConfig.KubernetesVersion
var err error

// Check dashboard status before enabling it
dashboardAddon := assets.Addons["dashboard"]
Expand All @@ -90,7 +88,7 @@ var dashboardCmd = &cobra.Command{
}

out.ErrT(out.Launch, "Launching proxy ...")
p, hostPort, err := kubectlProxy(kubectl, cname)
p, hostPort, err := kubectlProxy(kubectlVersion, cname)
if err != nil {
exit.WithError("kubectl proxy", err)
}
Expand Down Expand Up @@ -124,10 +122,17 @@ var dashboardCmd = &cobra.Command{
}

// kubectlProxy runs "kubectl proxy", returning host:port
func kubectlProxy(path string, contextName string) (*exec.Cmd, string, error) {
func kubectlProxy(kubectlVersion string, contextName string) (*exec.Cmd, string, error) {
// port=0 picks a random system port

cmd := exec.Command(path, "--context", contextName, "proxy", "--port=0")
kubectlArgs := []string{"--context", contextName, "proxy", "--port=0"}

var cmd *exec.Cmd
if kubectl, err := exec.LookPath("kubectl"); err == nil {
cmd = exec.Command(kubectl, kubectlArgs...)
} else if cmd, err = KubectlCommand(kubectlVersion, kubectlArgs...); err != nil {
return nil, "", err
}

stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions cmd/minikube/cmd/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,12 @@ minikube kubectl -- get pods --namespace kube-system`,
co := mustload.Healthy(ClusterFlagValue())

version := co.Config.KubernetesConfig.KubernetesVersion
if version == "" {
version = constants.DefaultKubernetesVersion
}

path, err := node.CacheKubectlBinary(version)
c, err := KubectlCommand(version, args...)
if err != nil {
out.ErrLn("Error caching kubectl: %v", err)
}

glog.Infof("Running %s %v", path, args)
c := exec.Command(path, args...)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
Expand All @@ -70,3 +65,17 @@ minikube kubectl -- get pods --namespace kube-system`,
}
},
}

// KubectlCommand will return kubectl command with a version matching the cluster
func KubectlCommand(version string, args ...string) (*exec.Cmd, error) {
if version == "" {
version = constants.DefaultKubernetesVersion
}

path, err := node.CacheKubectlBinary(version)
if err != nil {
return nil, err
}

return exec.Command(path, args...), nil
}