diff --git a/cmd/minikube/cmd/dashboard.go b/cmd/minikube/cmd/dashboard.go index 68fce8c86e01..141b3ab212e6 100644 --- a/cmd/minikube/cmd/dashboard.go +++ b/cmd/minikube/cmd/dashboard.go @@ -24,6 +24,7 @@ import ( "os/exec" "os/user" "regexp" + "strconv" "time" "github.com/pkg/errors" @@ -44,7 +45,8 @@ import ( ) var ( - dashboardURLMode bool + dashboardURLMode bool + dashboardExposedPort int // Matches: 127.0.0.1:8001 // TODO(tstromberg): Get kubectl to implement a stable supported output format. hostPortRe = regexp.MustCompile(`127.0.0.1:\d{4,}`) @@ -65,6 +67,10 @@ var dashboardCmd = &cobra.Command{ } } + if dashboardExposedPort < 0 || dashboardExposedPort > 65535 { + exit.Message(reason.HostKubectlProxy, "Invalid port") + } + kubectlVersion := co.Config.KubernetesConfig.KubernetesVersion var err error @@ -92,7 +98,7 @@ var dashboardCmd = &cobra.Command{ } out.ErrT(style.Launch, "Launching proxy ...") - p, hostPort, err := kubectlProxy(kubectlVersion, cname) + p, hostPort, err := kubectlProxy(kubectlVersion, cname, dashboardExposedPort) if err != nil { exit.Error(reason.HostKubectlProxy, "kubectl proxy", err) } @@ -126,10 +132,10 @@ var dashboardCmd = &cobra.Command{ } // kubectlProxy runs "kubectl proxy", returning host:port -func kubectlProxy(kubectlVersion string, contextName string) (*exec.Cmd, string, error) { +func kubectlProxy(kubectlVersion string, contextName string, port int) (*exec.Cmd, string, error) { // port=0 picks a random system port - kubectlArgs := []string{"--context", contextName, "proxy", "--port=0"} + kubectlArgs := []string{"--context", contextName, "proxy", "--port", strconv.Itoa(port)} var cmd *exec.Cmd if kubectl, err := exec.LookPath("kubectl"); err == nil { @@ -217,4 +223,5 @@ func checkURL(url string) error { func init() { dashboardCmd.Flags().BoolVar(&dashboardURLMode, "url", false, "Display dashboard URL instead of opening a browser") + dashboardCmd.Flags().IntVar(&dashboardExposedPort, "port", 0, "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.") } diff --git a/site/content/en/docs/commands/dashboard.md b/site/content/en/docs/commands/dashboard.md index b498a1adf7ef..c1e6557d2387 100644 --- a/site/content/en/docs/commands/dashboard.md +++ b/site/content/en/docs/commands/dashboard.md @@ -20,7 +20,8 @@ minikube dashboard [flags] ### Options ``` - --url Display dashboard URL instead of opening a browser + --port int Exposed port of the proxyfied dashboard. Set to 0 to pick a random port. + --url Display dashboard URL instead of opening a browser ``` ### Options inherited from parent commands diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index f7e62a41e38d..0670b4c5283c 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -815,7 +815,7 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) { mctx, cancel := context.WithTimeout(ctx, Seconds(300)) defer cancel() - args := []string{"dashboard", "--url", "-p", profile, "--alsologtostderr", "-v=1"} + args := []string{"dashboard", "--url", "--port", "36195", "-p", profile, "--alsologtostderr", "-v=1"} ss, err := Start(t, exec.CommandContext(mctx, Target(), args...)) if err != nil { t.Errorf("failed to run minikube dashboard. args %q : %v", args, err) diff --git a/translations/de.json b/translations/de.json index 66431d385d53..9ee74b5d0d22 100644 --- a/translations/de.json +++ b/translations/de.json @@ -215,6 +215,7 @@ "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Exiting": "Wird beendet", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "", diff --git a/translations/es.json b/translations/es.json index 6df86e67fc69..c9bf518e7a06 100644 --- a/translations/es.json +++ b/translations/es.json @@ -220,6 +220,7 @@ "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Exiting": "Saliendo", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "", diff --git a/translations/fr.json b/translations/fr.json index 5908baab5da2..432481c318d1 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -218,6 +218,7 @@ "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "Il manque de nouvelles fonctionnalités sur le disque existant ({{.error}}). Pour mettre à niveau, exécutez 'minikube delete'", "Exiting": "Fermeture…", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "Fermeture en raison de {{.fatal_code}} : {{.fatal_msg}}", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "L'adaptateur externe sur lequel un commutateur externe sera créé si aucun commutateur externe n'est trouvé. (pilote hyperv uniquement)", "Fail check if container paused": "Échec de la vérification si le conteneur est en pause", "Failed runtime": "Échec de l'exécution", diff --git a/translations/ja.json b/translations/ja.json index 64f78c1a9663..df7a36fdb99c 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -208,6 +208,7 @@ "Exiting": "終了しています", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "Exiting.": "終了しています", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "", diff --git a/translations/ko.json b/translations/ko.json index 6bfb6d2f906d..f3d6698e3560 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -232,6 +232,7 @@ "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "런타임이 실패하였습니다", diff --git a/translations/pl.json b/translations/pl.json index d6c6e83c42ba..060a59449079 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -223,6 +223,7 @@ "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "", diff --git a/translations/strings.txt b/translations/strings.txt index 3af38a3ba87a..2a5c665f0d55 100644 --- a/translations/strings.txt +++ b/translations/strings.txt @@ -201,6 +201,7 @@ "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "", diff --git a/translations/zh-CN.json b/translations/zh-CN.json index 1d80c63af25d..156687917636 100644 --- a/translations/zh-CN.json +++ b/translations/zh-CN.json @@ -280,6 +280,7 @@ "Exiting due to driver incompatibility": "由于驱动程序不兼容而退出", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "Exiting.": "正在退出。", + "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "", "Fail check if container paused": "", "Failed runtime": "",