From 755966080770b628caae074765fd79484faee13b Mon Sep 17 00:00:00 2001 From: zufardhiyaulhaq Date: Tue, 10 Jan 2023 19:05:24 +0700 Subject: [PATCH] introduce --open-browser flag on cilium hubble UI Signed-off-by: zufardhiyaulhaq --- hubble/hubble.go | 3 +++ hubble/ui.go | 14 +++++++++----- internal/cli/cmd/hubble.go | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hubble/hubble.go b/hubble/hubble.go index f923e84055..96fd8adc63 100644 --- a/hubble/hubble.go +++ b/hubble/hubble.go @@ -136,6 +136,9 @@ type Parameters struct { // RedactHelmCertKeys does not print helm certificate keys into the terminal. RedactHelmCertKeys bool + + // UIOpenBrowser will automatically open browser if true + UIOpenBrowser bool } func (p *Parameters) Log(format string, a ...interface{}) { diff --git a/hubble/ui.go b/hubble/ui.go index 657ac2360d..0f4d2b07df 100644 --- a/hubble/ui.go +++ b/hubble/ui.go @@ -247,11 +247,15 @@ func (p *Parameters) UIPortForwardCommand(ctx context.Context) error { time.Sleep(5 * time.Second) url := fmt.Sprintf("http://localhost:%d", p.UIPortForward) - // avoid cluttering stdout/stderr when opening the browser - browser.Stdout = io.Discard - browser.Stderr = io.Discard - p.Log("ℹ️ Opening %q in your browser...", url) - browser.OpenURL(url) + if p.UIOpenBrowser { + // avoid cluttering stdout/stderr when opening the browser + browser.Stdout = io.Discard + browser.Stderr = io.Discard + p.Log("ℹ️ Opening %q in your browser...", url) + browser.OpenURL(url) + } else { + p.Log("ℹ️ Hubble UI is available at %q", url) + } }() _, err := utils.Exec(p, "kubectl", args...) diff --git a/internal/cli/cmd/hubble.go b/internal/cli/cmd/hubble.go index c98f5f1a20..e61a343713 100644 --- a/internal/cli/cmd/hubble.go +++ b/internal/cli/cmd/hubble.go @@ -175,6 +175,7 @@ func newCmdUI() *cobra.Command { } cmd.Flags().IntVar(¶ms.UIPortForward, "port-forward", 12000, "Local port to use for the port forward") + cmd.Flags().BoolVar(¶ms.UIOpenBrowser, "open-browser", true, "When --open-browser=false is supplied, cilium Hubble UI will not open the browser") return cmd }