From 30fce5d76583466ee1ec018c8620fcd46bad3b5a Mon Sep 17 00:00:00 2001 From: Igor Gov Date: Tue, 5 Oct 2021 12:24:50 +0300 Subject: [PATCH] Supporting Mizu view from given url (#312) * Supporting Mizu view from given url --- cli/cmd/view.go | 3 ++ cli/cmd/viewRunner.go | 49 ++++++++++++++------------ cli/config/configStructs/viewConfig.go | 2 ++ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/cli/cmd/view.go b/cli/cmd/view.go index a8379cf42..b3bf31f67 100644 --- a/cli/cmd/view.go +++ b/cli/cmd/view.go @@ -25,4 +25,7 @@ func init() { defaults.Set(&defaultViewConfig) viewCmd.Flags().Uint16P(configStructs.GuiPortViewName, "p", defaultViewConfig.GuiPort, "Provide a custom port for the web interface webserver") + viewCmd.Flags().StringP(configStructs.UrlViewName, "u", defaultViewConfig.Url, "Provide a custom host") + + viewCmd.Flags().MarkHidden(configStructs.UrlViewName) } diff --git a/cli/cmd/viewRunner.go b/cli/cmd/viewRunner.go index 7938d62ee..63ce6d695 100644 --- a/cli/cmd/viewRunner.go +++ b/cli/cmd/viewRunner.go @@ -24,34 +24,39 @@ func runMizuView() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - exists, err := kubernetesProvider.DoesServicesExist(ctx, config.Config.MizuResourcesNamespace, mizu.ApiServerPodName) - if err != nil { - logger.Log.Errorf("Failed to found mizu service %v", err) - cancel() - return - } - if !exists { - logger.Log.Infof("%s service not found, you should run `mizu tap` command first", mizu.ApiServerPodName) - cancel() - return - } + url := config.Config.View.Url - url := GetApiServerUrl() + if url == "" { + exists, err := kubernetesProvider.DoesServicesExist(ctx, config.Config.MizuResourcesNamespace, mizu.ApiServerPodName) + if err != nil { + logger.Log.Errorf("Failed to found mizu service %v", err) + cancel() + return + } + if !exists { + logger.Log.Infof("%s service not found, you should run `mizu tap` command first", mizu.ApiServerPodName) + cancel() + return + } - response, err := http.Get(fmt.Sprintf("%s/", url)) - if err == nil && response.StatusCode == 200 { - logger.Log.Infof("Found a running service %s and open port %d", mizu.ApiServerPodName, config.Config.View.GuiPort) - return - } - logger.Log.Infof("Establishing connection to k8s cluster...") - go startProxyReportErrorIfAny(kubernetesProvider, cancel) + url = GetApiServerUrl() - if err := apiserver.Provider.InitAndTestConnection(GetApiServerUrl()); err != nil { - logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Couldn't connect to API server, for more info check logs at %s", logger.GetLogFilePath())) - return + response, err := http.Get(fmt.Sprintf("%s/", url)) + if err == nil && response.StatusCode == 200 { + logger.Log.Infof("Found a running service %s and open port %d", mizu.ApiServerPodName, config.Config.View.GuiPort) + return + } + logger.Log.Infof("Establishing connection to k8s cluster...") + go startProxyReportErrorIfAny(kubernetesProvider, cancel) + + if err := apiserver.Provider.InitAndTestConnection(GetApiServerUrl()); err != nil { + logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Couldn't connect to API server, for more info check logs at %s", logger.GetLogFilePath())) + return + } } logger.Log.Infof("Mizu is available at %s\n", url) + openBrowser(url) if isCompatible, err := version.CheckVersionCompatibility(); err != nil { logger.Log.Errorf("Failed to check versions compatibility %v", err) diff --git a/cli/config/configStructs/viewConfig.go b/cli/config/configStructs/viewConfig.go index aa41a7353..0337680c8 100644 --- a/cli/config/configStructs/viewConfig.go +++ b/cli/config/configStructs/viewConfig.go @@ -2,8 +2,10 @@ package configStructs const ( GuiPortViewName = "gui-port" + UrlViewName = "url" ) type ViewConfig struct { GuiPort uint16 `yaml:"gui-port" default:"8899"` + Url string `yaml:"url,omitempty" readonly:""` }