Skip to content

Commit

Permalink
feat: flag for skipping opening browser for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ed382 committed Sep 5, 2024
1 parent 9dc3a40 commit 8990a39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions cmd/kubectl-testkube/commands/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const maxPortNumber = 65535
func NewDashboardCmd() *cobra.Command {
var namespace string
var verbose bool
var skipBrowser bool

cmd := &cobra.Command{
Use: "dashboard",
Expand All @@ -40,7 +41,7 @@ func NewDashboardCmd() *cobra.Command {
if cfg.ContextType != config.ContextTypeCloud {
isDashboardRunning, _ := k8sclient.IsPodOfServiceRunning(context.Background(), cfg.Namespace, config.EnterpriseUiName)
if isDashboardRunning {
openOnPremDashboard(cmd, cfg, verbose, "")
openOnPremDashboard(cmd, cfg, verbose, skipBrowser, "")
} else {
ui.Warn("No dashboard found. Is it running in the " + namespace + " namespace?")
}
Expand All @@ -52,6 +53,7 @@ func NewDashboardCmd() *cobra.Command {

cmd.Flags().BoolVarP(&verbose, "verbose", "", false, "show additional debug messages")
cmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace to install "+demoInstallationName)
cmd.Flags().BoolVarP(&skipBrowser, "skip-browser", "", false, "skip opening dashboard in the browser, only for on-premise installation")

return cmd
}
Expand All @@ -63,7 +65,7 @@ func openCloudDashboard(cfg config.Data) {
ui.PrintOnError("openning dashboard", err)
}

func openOnPremDashboard(cmd *cobra.Command, cfg config.Data, verbose bool, license string) {
func openOnPremDashboard(cmd *cobra.Command, cfg config.Data, verbose, skipBrowser bool, license string) {
uiLocalPort, err := getDashboardLocalPort(config.EnterpriseApiForwardingPort)
ui.PrintOnError("getting an ui forwarding available port", err)
uri := fmt.Sprintf("http://localhost:%d", uiLocalPort)
Expand Down Expand Up @@ -91,14 +93,16 @@ func openOnPremDashboard(cmd *cobra.Command, cfg config.Data, verbose bool, lice
}
ui.ExitOnError("port forwarding minio", err)

err = open.Run(uri)
if err != nil {
sendErrTelemetry(cmd, cfg, "open_dashboard", license, "opening dashboard", err)
}
if !skipBrowser {
err = open.Run(uri)
if err != nil {
sendErrTelemetry(cmd, cfg, "open_dashboard", license, "opening dashboard", err)
}

ui.ExitOnError("opening dashboard in browser", err)
ui.ExitOnError("opening dashboard in browser", err)

sendTelemetry(cmd, cfg, license, "dashbboard opened successfully")
sendTelemetry(cmd, cfg, license, "dashbboard opened successfully")
}

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func NewInitCmdDemo() *cobra.Command {
sendTelemetry(cmd, cfg, license, "opening dashboard")
cfg, err = config.Load()
ui.ExitOnError("Cannot open dashboard", err)
openOnPremDashboard(cmd, cfg, false, license)
openOnPremDashboard(cmd, cfg, false, false, license)
},
}

Expand Down

0 comments on commit 8990a39

Please sign in to comment.