Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flag for skipping opening browser for dashboard #5818

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading