diff --git a/cmd/console.go b/cmd/console.go index 395f5bc63..42dc6359a 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -45,7 +45,7 @@ func runConsole() { response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl)) if err != nil || response.StatusCode != 200 { log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy...")) - runProxy(false) + runProxy(false, true) } interrupt := make(chan os.Signal, 1) diff --git a/cmd/pro.go b/cmd/pro.go index e4dfee6ff..34e22685c 100644 --- a/cmd/pro.go +++ b/cmd/pro.go @@ -49,7 +49,7 @@ func acquireLicense() { response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl)) if err != nil || response.StatusCode != 200 { log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy...")) - runProxy(false) + runProxy(false, true) } connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort), connect.DefaultRetries, connect.DefaultTimeout) @@ -64,7 +64,7 @@ func updateLicense(licenseKey string) { config.Config.License = licenseKey err := config.WriteConfig(&config.Config) if err != nil { - log.Warn().Err(err).Send() + log.Error().Err(err).Send() } go func() { diff --git a/cmd/proxy.go b/cmd/proxy.go index 833163b30..fbfa75479 100644 --- a/cmd/proxy.go +++ b/cmd/proxy.go @@ -11,7 +11,7 @@ var proxyCmd = &cobra.Command{ Use: "proxy", Short: "Open the web UI (front-end) in the browser via proxy/port-forward", RunE: func(cmd *cobra.Command, args []string) error { - runProxy(true) + runProxy(true, false) return nil }, } diff --git a/cmd/proxyRunner.go b/cmd/proxyRunner.go index 809dfb2ff..5d4343ca9 100644 --- a/cmd/proxyRunner.go +++ b/cmd/proxyRunner.go @@ -14,7 +14,7 @@ import ( "github.com/rs/zerolog/log" ) -func runProxy(block bool) { +func runProxy(block bool, noBrowser bool) { kubernetesProvider, err := getKubernetesProviderForCli() if err != nil { return @@ -101,7 +101,7 @@ func runProxy(block bool) { Int("port", int(config.Config.Tap.Proxy.Front.SrcPort)). Msg("Found a running service.") - okToOpen("Kubeshark", frontUrl, false) + okToOpen("Kubeshark", frontUrl, noBrowser) } else { startProxyReportErrorIfAny( kubernetesProvider, @@ -120,7 +120,7 @@ func runProxy(block bool) { } establishedProxy = true - okToOpen("Kubeshark", frontUrl, false) + okToOpen("Kubeshark", frontUrl, noBrowser) } if establishedProxy && block { diff --git a/cmd/scripts.go b/cmd/scripts.go index 34f6d3504..b17a15f52 100644 --- a/cmd/scripts.go +++ b/cmd/scripts.go @@ -48,7 +48,7 @@ func runScripts() { response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl)) if err != nil || response.StatusCode != 200 { log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy...")) - runProxy(false) + runProxy(false, true) } connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort), connect.DefaultRetries, connect.DefaultTimeout) diff --git a/config/config.go b/config/config.go index 4f10a5028..2c0f9d4be 100644 --- a/config/config.go +++ b/config/config.go @@ -63,11 +63,11 @@ func InitConfig(cmd *cobra.Command) error { } configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName) - configFilePath := configFilePathFlag.Value.String() - if err := loadConfigFile(configFilePath, &Config); err != nil { + ConfigFilePath = configFilePathFlag.Value.String() + if err := loadConfigFile(&Config); err != nil { if configFilePathFlag.Changed || !os.IsNotExist(err) { return fmt.Errorf("invalid config, %w\n"+ - "you can regenerate the file by removing it (%v) and using `kubeshark config -r`", err, configFilePath) + "you can regenerate the file by removing it (%v) and using `kubeshark config -r`", err, ConfigFilePath) } } @@ -104,7 +104,7 @@ func WriteConfig(config *ConfigStruct) error { return nil } -func loadConfigFile(configFilePath string, config *ConfigStruct) error { +func loadConfigFile(config *ConfigStruct) error { cwd, err := os.Getwd() if err != nil { return err @@ -113,12 +113,12 @@ func loadConfigFile(configFilePath string, config *ConfigStruct) error { cwdConfig := filepath.Join(cwd, fmt.Sprintf("%s.yaml", misc.Program)) reader, err := os.Open(cwdConfig) if err != nil { - reader, err = os.Open(configFilePath) + reader, err = os.Open(ConfigFilePath) if err != nil { return err } } else { - configFilePath = cwdConfig + ConfigFilePath = cwdConfig } buf, err := io.ReadAll(reader) @@ -130,8 +130,7 @@ func loadConfigFile(configFilePath string, config *ConfigStruct) error { return err } - ConfigFilePath = configFilePath - log.Info().Str("path", configFilePath).Msg("Found config file!") + log.Info().Str("path", ConfigFilePath).Msg("Found config file!") return nil }