mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-01 10:36:55 +00:00
🐛 Fix the issues in pro
, console
, proxy
, config
and scripts
commands
This commit is contained in:
@@ -45,7 +45,7 @@ func runConsole() {
|
|||||||
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
||||||
if err != nil || response.StatusCode != 200 {
|
if err != nil || response.StatusCode != 200 {
|
||||||
log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy..."))
|
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)
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
@@ -49,7 +49,7 @@ func acquireLicense() {
|
|||||||
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
||||||
if err != nil || response.StatusCode != 200 {
|
if err != nil || response.StatusCode != 200 {
|
||||||
log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy..."))
|
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)
|
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
|
config.Config.License = licenseKey
|
||||||
err := config.WriteConfig(&config.Config)
|
err := config.WriteConfig(&config.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Send()
|
log.Error().Err(err).Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@@ -11,7 +11,7 @@ var proxyCmd = &cobra.Command{
|
|||||||
Use: "proxy",
|
Use: "proxy",
|
||||||
Short: "Open the web UI (front-end) in the browser via proxy/port-forward",
|
Short: "Open the web UI (front-end) in the browser via proxy/port-forward",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
runProxy(true)
|
runProxy(true, false)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runProxy(block bool) {
|
func runProxy(block bool, noBrowser bool) {
|
||||||
kubernetesProvider, err := getKubernetesProviderForCli()
|
kubernetesProvider, err := getKubernetesProviderForCli()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -101,7 +101,7 @@ func runProxy(block bool) {
|
|||||||
Int("port", int(config.Config.Tap.Proxy.Front.SrcPort)).
|
Int("port", int(config.Config.Tap.Proxy.Front.SrcPort)).
|
||||||
Msg("Found a running service.")
|
Msg("Found a running service.")
|
||||||
|
|
||||||
okToOpen("Kubeshark", frontUrl, false)
|
okToOpen("Kubeshark", frontUrl, noBrowser)
|
||||||
} else {
|
} else {
|
||||||
startProxyReportErrorIfAny(
|
startProxyReportErrorIfAny(
|
||||||
kubernetesProvider,
|
kubernetesProvider,
|
||||||
@@ -120,7 +120,7 @@ func runProxy(block bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
establishedProxy = true
|
establishedProxy = true
|
||||||
okToOpen("Kubeshark", frontUrl, false)
|
okToOpen("Kubeshark", frontUrl, noBrowser)
|
||||||
}
|
}
|
||||||
|
|
||||||
if establishedProxy && block {
|
if establishedProxy && block {
|
||||||
|
@@ -48,7 +48,7 @@ func runScripts() {
|
|||||||
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
response, err := http.Get(fmt.Sprintf("%s/echo", hubUrl))
|
||||||
if err != nil || response.StatusCode != 200 {
|
if err != nil || response.StatusCode != 200 {
|
||||||
log.Info().Msg(fmt.Sprintf(utils.Yellow, "Couldn't connect to Hub. Establishing proxy..."))
|
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)
|
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
|
@@ -63,11 +63,11 @@ func InitConfig(cmd *cobra.Command) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
|
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
|
||||||
configFilePath := configFilePathFlag.Value.String()
|
ConfigFilePath = configFilePathFlag.Value.String()
|
||||||
if err := loadConfigFile(configFilePath, &Config); err != nil {
|
if err := loadConfigFile(&Config); err != nil {
|
||||||
if configFilePathFlag.Changed || !os.IsNotExist(err) {
|
if configFilePathFlag.Changed || !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("invalid config, %w\n"+
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfigFile(configFilePath string, config *ConfigStruct) error {
|
func loadConfigFile(config *ConfigStruct) error {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -113,12 +113,12 @@ func loadConfigFile(configFilePath string, config *ConfigStruct) error {
|
|||||||
cwdConfig := filepath.Join(cwd, fmt.Sprintf("%s.yaml", misc.Program))
|
cwdConfig := filepath.Join(cwd, fmt.Sprintf("%s.yaml", misc.Program))
|
||||||
reader, err := os.Open(cwdConfig)
|
reader, err := os.Open(cwdConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reader, err = os.Open(configFilePath)
|
reader, err = os.Open(ConfigFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
configFilePath = cwdConfig
|
ConfigFilePath = cwdConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := io.ReadAll(reader)
|
buf, err := io.ReadAll(reader)
|
||||||
@@ -130,8 +130,7 @@ func loadConfigFile(configFilePath string, config *ConfigStruct) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigFilePath = configFilePath
|
log.Info().Str("path", ConfigFilePath).Msg("Found config file!")
|
||||||
log.Info().Str("path", configFilePath).Msg("Found config file!")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user