From dcd42798c7505bd2487a9926b91ee235defa6e81 Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Wed, 15 Feb 2023 00:56:33 +0300 Subject: [PATCH] :sparkles: Establish a proxy in `console` command if it's not present --- cmd/console.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/console.go b/cmd/console.go index 332640a06..857cba7ff 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "net/http" "net/url" "os" "os/signal" @@ -12,6 +13,7 @@ import ( "github.com/gorilla/websocket" "github.com/kubeshark/kubeshark/config" "github.com/kubeshark/kubeshark/config/configStructs" + "github.com/kubeshark/kubeshark/kubernetes" "github.com/kubeshark/kubeshark/utils" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -39,6 +41,13 @@ func init() { } func runConsole() { + hubUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort) + 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) + } + interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) @@ -52,6 +61,7 @@ func runConsole() { c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { log.Error().Err(err).Send() + return } defer c.Close()