🐛 Fix the issues in pro, console, proxy, config and scripts commands

This commit is contained in:
M. Mert Yildiran
2023-03-19 18:39:22 +03:00
parent abc506af1a
commit 0dac046f57
6 changed files with 15 additions and 16 deletions

View File

@@ -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)

View File

@@ -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() {

View File

@@ -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
},
}

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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
}