Allow to set the dashboard proxyfied port

pull/11553/head
Alexandre Garnier 2021-06-01 15:22:15 +02:00 committed by Alexandre Garnier
parent 27d738657c
commit f76b0795d8
10 changed files with 17 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import (
"os/exec" "os/exec"
"os/user" "os/user"
"regexp" "regexp"
"strconv"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -44,7 +45,8 @@ import (
) )
var ( var (
dashboardURLMode bool dashboardURLMode bool
dashboardExposedPort int
// Matches: 127.0.0.1:8001 // Matches: 127.0.0.1:8001
// TODO(tstromberg): Get kubectl to implement a stable supported output format. // TODO(tstromberg): Get kubectl to implement a stable supported output format.
hostPortRe = regexp.MustCompile(`127.0.0.1:\d{4,}`) hostPortRe = regexp.MustCompile(`127.0.0.1:\d{4,}`)
@ -92,7 +94,7 @@ var dashboardCmd = &cobra.Command{
} }
out.ErrT(style.Launch, "Launching proxy ...") out.ErrT(style.Launch, "Launching proxy ...")
p, hostPort, err := kubectlProxy(kubectlVersion, cname) p, hostPort, err := kubectlProxy(kubectlVersion, cname, dashboardExposedPort)
if err != nil { if err != nil {
exit.Error(reason.HostKubectlProxy, "kubectl proxy", err) exit.Error(reason.HostKubectlProxy, "kubectl proxy", err)
} }
@ -126,10 +128,10 @@ var dashboardCmd = &cobra.Command{
} }
// kubectlProxy runs "kubectl proxy", returning host:port // 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 // 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 var cmd *exec.Cmd
if kubectl, err := exec.LookPath("kubectl"); err == nil { if kubectl, err := exec.LookPath("kubectl"); err == nil {
@ -217,4 +219,5 @@ func checkURL(url string) error {
func init() { func init() {
dashboardCmd.Flags().BoolVar(&dashboardURLMode, "url", false, "Display dashboard URL instead of opening a browser") 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.")
} }

View File

@ -20,7 +20,8 @@ minikube dashboard [flags]
### Options ### 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 ### Options inherited from parent commands

View File

@ -215,6 +215,7 @@
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
"Exiting": "Wird beendet", "Exiting": "Wird beendet",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",

View File

@ -220,6 +220,7 @@
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
"Exiting": "Saliendo", "Exiting": "Saliendo",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",

View File

@ -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'", "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": "Fermeture…",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "Fermeture en raison de {{.fatal_code}} : {{.fatal_msg}}", "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)", "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", "Fail check if container paused": "Échec de la vérification si le conteneur est en pause",
"Failed runtime": "Échec de l'exécution", "Failed runtime": "Échec de l'exécution",

View File

@ -208,6 +208,7 @@
"Exiting": "終了しています", "Exiting": "終了しています",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
"Exiting.": "終了しています", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",

View File

@ -232,6 +232,7 @@
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "런타임이 실패하였습니다", "Failed runtime": "런타임이 실패하였습니다",

View File

@ -223,6 +223,7 @@
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",

View File

@ -201,6 +201,7 @@
"Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "", "Executing \"{{.command}}\" took an unusually long time: {{.duration}}": "",
"Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "", "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'": "",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",

View File

@ -280,6 +280,7 @@
"Exiting due to driver incompatibility": "由于驱动程序不兼容而退出", "Exiting due to driver incompatibility": "由于驱动程序不兼容而退出",
"Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "", "Exiting due to {{.fatal_code}}: {{.fatal_msg}}": "",
"Exiting.": "正在退出。", "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)": "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)": "",
"Fail check if container paused": "", "Fail check if container paused": "",
"Failed runtime": "", "Failed runtime": "",