Skip to content

Commit

Permalink
introduce --open-browser flag on cilium hubble UI
Browse files Browse the repository at this point in the history
Signed-off-by: zufardhiyaulhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq authored and tklauser committed Jan 10, 2023
1 parent 90e7cca commit 7559660
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions hubble/hubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
14 changes: 9 additions & 5 deletions hubble/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
1 change: 1 addition & 0 deletions internal/cli/cmd/hubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func newCmdUI() *cobra.Command {
}

cmd.Flags().IntVar(&params.UIPortForward, "port-forward", 12000, "Local port to use for the port forward")
cmd.Flags().BoolVar(&params.UIOpenBrowser, "open-browser", true, "When --open-browser=false is supplied, cilium Hubble UI will not open the browser")

return cmd
}

0 comments on commit 7559660

Please sign in to comment.