mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-20 21:44:42 +00:00
Added the scripting console
command functionality to the tap
command
Added both the `scripting` and `console` commands to the `proxy` command Added a `scripting.console`, a boolean value indicating whether the `console` functionality should be part of the `tap` and `proxy` commands
This commit is contained in:
parent
ecc577ccc8
commit
41f36ba9c2
@ -41,13 +41,15 @@ func init() {
|
|||||||
consoleCmd.Flags().StringP(configStructs.ReleaseNamespaceLabel, "s", defaultTapConfig.Release.Namespace, "Release namespace of Kubeshark")
|
consoleCmd.Flags().StringP(configStructs.ReleaseNamespaceLabel, "s", defaultTapConfig.Release.Namespace, "Release namespace of Kubeshark")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConsole() {
|
func runConsoleWithoutProxy() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
for {
|
for {
|
||||||
hubUrl := kubernetes.GetHubUrl()
|
hubUrl := kubernetes.GetHubUrl()
|
||||||
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."))
|
||||||
runProxy(false, true)
|
time.Sleep(5 * time.Second)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
@ -101,8 +103,6 @@ func runConsole() {
|
|||||||
time.Sleep(5 * time.Second) // Delay before reconnecting
|
time.Sleep(5 * time.Second) // Delay before reconnecting
|
||||||
continue // Reconnect after error
|
continue // Reconnect after error
|
||||||
case <-interrupt:
|
case <-interrupt:
|
||||||
log.Warn().Msg(fmt.Sprintf(utils.Yellow, "Received interrupt, exiting..."))
|
|
||||||
|
|
||||||
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Send()
|
log.Error().Err(err).Send()
|
||||||
@ -117,3 +117,32 @@ func runConsole() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runConsole() {
|
||||||
|
go runConsoleWithoutProxy()
|
||||||
|
for {
|
||||||
|
hubUrl := kubernetes.GetHubUrl()
|
||||||
|
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, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
ticker := time.NewTicker(time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
select { // Reconnect after error
|
||||||
|
case <-interrupt:
|
||||||
|
log.Warn().Msg(fmt.Sprintf(utils.Yellow, "Received interrupt, exiting..."))
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -92,10 +92,17 @@ func runProxy(block bool, noBrowser bool) {
|
|||||||
establishedProxy = true
|
establishedProxy = true
|
||||||
okToOpen("Kubeshark", frontUrl, noBrowser)
|
okToOpen("Kubeshark", frontUrl, noBrowser)
|
||||||
}
|
}
|
||||||
|
if config.Config.Scripting.Source != "" && config.Config.Scripting.WatchScripts {
|
||||||
|
watchScripts(kubernetesProvider, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Config.Scripting.Console {
|
||||||
|
go runConsoleWithoutProxy()
|
||||||
|
}
|
||||||
if establishedProxy && block {
|
if establishedProxy && block {
|
||||||
utils.WaitForTermination(ctx, cancel)
|
utils.WaitForTermination(ctx, cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func okToOpen(name string, url string, noBrowser bool) {
|
func okToOpen(name string, url string, noBrowser bool) {
|
||||||
|
@ -427,6 +427,10 @@ func postFrontStarted(ctx context.Context, kubernetesProvider *kubernetes.Provid
|
|||||||
if config.Config.Scripting.Source != "" && config.Config.Scripting.WatchScripts {
|
if config.Config.Scripting.Source != "" && config.Config.Scripting.WatchScripts {
|
||||||
watchScripts(kubernetesProvider, false)
|
watchScripts(kubernetesProvider, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Config.Scripting.Console {
|
||||||
|
go runConsoleWithoutProxy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateConfig(kubernetesProvider *kubernetes.Provider) {
|
func updateConfig(kubernetesProvider *kubernetes.Provider) {
|
||||||
|
@ -14,6 +14,7 @@ type ScriptingConfig struct {
|
|||||||
Env map[string]interface{} `yaml:"env" json:"env" default:"{}"`
|
Env map[string]interface{} `yaml:"env" json:"env" default:"{}"`
|
||||||
Source string `yaml:"source" json:"source" default:""`
|
Source string `yaml:"source" json:"source" default:""`
|
||||||
WatchScripts bool `yaml:"watchScripts" json:"watchScripts" default:"true"`
|
WatchScripts bool `yaml:"watchScripts" json:"watchScripts" default:"true"`
|
||||||
|
Console bool `yaml:"console" json:"console" default:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ScriptingConfig) GetScripts() (scripts []*misc.Script, err error) {
|
func (config *ScriptingConfig) GetScripts() (scripts []*misc.Script, err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user