Skip to content

Commit

Permalink
Merge pull request #11553 from zigarn/dashboard-set-port
Browse files Browse the repository at this point in the history
Allow to set the dashboard proxyfied port
  • Loading branch information
spowelljr authored Jul 12, 2021
2 parents f40b6ea + 97c7a1e commit 961bbbe
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 6 deletions.
15 changes: 11 additions & 4 deletions cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os/exec"
"os/user"
"regexp"
"strconv"
"time"

"github.com/pkg/errors"
Expand All @@ -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,}`)
Expand All @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.")
}
3 changes: 2 additions & 1 deletion site/content/en/docs/commands/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "런타임이 실패하였습니다",
Expand Down
1 change: 1 addition & 0 deletions translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
1 change: 1 addition & 0 deletions translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down

0 comments on commit 961bbbe

Please sign in to comment.