Skip to content

Commit 961bbbe

Browse files
authored
Merge pull request #11553 from zigarn/dashboard-set-port
Allow to set the dashboard proxyfied port
2 parents f40b6ea + 97c7a1e commit 961bbbe

File tree

11 files changed

+22
-6
lines changed

11 files changed

+22
-6
lines changed

cmd/minikube/cmd/dashboard.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os/exec"
2525
"os/user"
2626
"regexp"
27+
"strconv"
2728
"time"
2829

2930
"github.com/pkg/errors"
@@ -44,7 +45,8 @@ import (
4445
)
4546

4647
var (
47-
dashboardURLMode bool
48+
dashboardURLMode bool
49+
dashboardExposedPort int
4850
// Matches: 127.0.0.1:8001
4951
// TODO(tstromberg): Get kubectl to implement a stable supported output format.
5052
hostPortRe = regexp.MustCompile(`127.0.0.1:\d{4,}`)
@@ -65,6 +67,10 @@ var dashboardCmd = &cobra.Command{
6567
}
6668
}
6769

70+
if dashboardExposedPort < 0 || dashboardExposedPort > 65535 {
71+
exit.Message(reason.HostKubectlProxy, "Invalid port")
72+
}
73+
6874
kubectlVersion := co.Config.KubernetesConfig.KubernetesVersion
6975
var err error
7076

@@ -92,7 +98,7 @@ var dashboardCmd = &cobra.Command{
9298
}
9399

94100
out.ErrT(style.Launch, "Launching proxy ...")
95-
p, hostPort, err := kubectlProxy(kubectlVersion, cname)
101+
p, hostPort, err := kubectlProxy(kubectlVersion, cname, dashboardExposedPort)
96102
if err != nil {
97103
exit.Error(reason.HostKubectlProxy, "kubectl proxy", err)
98104
}
@@ -126,10 +132,10 @@ var dashboardCmd = &cobra.Command{
126132
}
127133

128134
// kubectlProxy runs "kubectl proxy", returning host:port
129-
func kubectlProxy(kubectlVersion string, contextName string) (*exec.Cmd, string, error) {
135+
func kubectlProxy(kubectlVersion string, contextName string, port int) (*exec.Cmd, string, error) {
130136
// port=0 picks a random system port
131137

132-
kubectlArgs := []string{"--context", contextName, "proxy", "--port=0"}
138+
kubectlArgs := []string{"--context", contextName, "proxy", "--port", strconv.Itoa(port)}
133139

134140
var cmd *exec.Cmd
135141
if kubectl, err := exec.LookPath("kubectl"); err == nil {
@@ -217,4 +223,5 @@ func checkURL(url string) error {
217223

218224
func init() {
219225
dashboardCmd.Flags().BoolVar(&dashboardURLMode, "url", false, "Display dashboard URL instead of opening a browser")
226+
dashboardCmd.Flags().IntVar(&dashboardExposedPort, "port", 0, "Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.")
220227
}

site/content/en/docs/commands/dashboard.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ minikube dashboard [flags]
2020
### Options
2121

2222
```
23-
--url Display dashboard URL instead of opening a browser
23+
--port int Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.
24+
--url Display dashboard URL instead of opening a browser
2425
```
2526

2627
### Options inherited from parent commands

test/integration/functional_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ func validateDashboardCmd(ctx context.Context, t *testing.T, profile string) {
815815
mctx, cancel := context.WithTimeout(ctx, Seconds(300))
816816
defer cancel()
817817

818-
args := []string{"dashboard", "--url", "-p", profile, "--alsologtostderr", "-v=1"}
818+
args := []string{"dashboard", "--url", "--port", "36195", "-p", profile, "--alsologtostderr", "-v=1"}
819819
ss, err := Start(t, exec.CommandContext(mctx, Target(), args...))
820820
if err != nil {
821821
t.Errorf("failed to run minikube dashboard. args %q : %v", args, err)

translations/de.json

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
216216
"Exiting": "Wird beendet",
217217
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
218+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
218219
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
219220
"Fail check if container paused": "",
220221
"Failed runtime": "",

translations/es.json

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
221221
"Exiting": "Saliendo",
222222
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
223+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
223224
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
224225
"Fail check if container paused": "",
225226
"Failed runtime": "",

translations/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
"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'",
219219
"Exiting": "Fermeture…",
220220
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "Fermeture en raison de {{.fatal_code}} : {{.fatal_msg}}",
221+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
221222
"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)",
222223
"Fail check if container paused": "Échec de la vérification si le conteneur est en pause",
223224
"Failed runtime": "Échec de l'exécution",

translations/ja.json

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
"Exiting": "終了しています",
209209
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
210210
"Exiting.": "終了しています",
211+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
211212
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
212213
"Fail check if container paused": "",
213214
"Failed runtime": "",

translations/ko.json

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
233233
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
234234
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
235+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
235236
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
236237
"Fail check if container paused": "",
237238
"Failed runtime": "런타임이 실패하였습니다",

translations/pl.json

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
224224
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
225225
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
226+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
226227
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
227228
"Fail check if container paused": "",
228229
"Failed runtime": "",

translations/strings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
202202
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
203203
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
204+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
204205
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
205206
"Fail check if container paused": "",
206207
"Failed runtime": "",

translations/zh-CN.json

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
"Exiting due to driver incompatibility": "由于驱动程序不兼容而退出",
281281
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
282282
"Exiting.": "正在退出。",
283+
"Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.": "",
283284
"External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
284285
"Fail check if container paused": "",
285286
"Failed runtime": "",

0 commit comments

Comments
 (0)