mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-03 19:48:45 +00:00
⚡ Change GetLocalhostOnPort
method to GetProxyOnPort
This commit is contained in:
@@ -26,7 +26,7 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connector := connect.NewConnector(kubernetes.GetLocalhostOnPort(srcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
connector := connect.NewConnector(kubernetes.GetProxyOnPort(srcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
if err := connector.TestConnection(healthCheck); err != nil {
|
if err := connector.TestConnection(healthCheck); err != nil {
|
||||||
log.Warn().
|
log.Warn().
|
||||||
Str("service", serviceName).
|
Str("service", serviceName).
|
||||||
@@ -46,7 +46,7 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(srcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
connector = connect.NewConnector(kubernetes.GetProxyOnPort(srcPort), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
if err := connector.TestConnection(healthCheck); err != nil {
|
if err := connector.TestConnection(healthCheck); err != nil {
|
||||||
log.Error().
|
log.Error().
|
||||||
Str("service", serviceName).
|
Str("service", serviceName).
|
||||||
|
@@ -41,7 +41,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runConsole() {
|
func runConsole() {
|
||||||
hubUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)
|
hubUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)
|
||||||
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..."))
|
||||||
|
@@ -45,14 +45,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func acquireLicense() {
|
func acquireLicense() {
|
||||||
hubUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)
|
hubUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)
|
||||||
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, true)
|
runProxy(false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
connector = connect.NewConnector(kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
|
|
||||||
log.Info().Str("url", PRO_URL).Msg("Opening in the browser:")
|
log.Info().Str("url", PRO_URL).Msg("Opening in the browser:")
|
||||||
utils.OpenBrowser(PRO_URL)
|
utils.OpenBrowser(PRO_URL)
|
||||||
|
@@ -63,7 +63,7 @@ func runProxy(block bool, noBrowser bool) {
|
|||||||
|
|
||||||
var establishedProxy bool
|
var establishedProxy bool
|
||||||
|
|
||||||
hubUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)
|
hubUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)
|
||||||
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().
|
log.Info().
|
||||||
@@ -93,7 +93,7 @@ func runProxy(block bool, noBrowser bool) {
|
|||||||
okToOpen("Hub", hubUrl, true)
|
okToOpen("Hub", hubUrl, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
frontUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Front.Port)
|
frontUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Front.Port)
|
||||||
response, err = http.Get(fmt.Sprintf("%s/", frontUrl))
|
response, err = http.Get(fmt.Sprintf("%s/", frontUrl))
|
||||||
if err == nil && response.StatusCode == 200 {
|
if err == nil && response.StatusCode == 200 {
|
||||||
log.Info().
|
log.Info().
|
||||||
|
@@ -44,14 +44,14 @@ func runScripts() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hubUrl := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)
|
hubUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)
|
||||||
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, true)
|
runProxy(false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
connector = connect.NewConnector(kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
|
|
||||||
watchScripts(true)
|
watchScripts(true)
|
||||||
}
|
}
|
||||||
|
@@ -329,7 +329,7 @@ func pcap(tarPath string) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
connector = connect.NewConnector(kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
connector.PostWorkerPodToHub(workerPod)
|
connector.PostWorkerPodToHub(workerPod)
|
||||||
|
|
||||||
// License
|
// License
|
||||||
@@ -338,10 +338,10 @@ func pcap(tarPath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("url", kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)).
|
Str("url", kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)).
|
||||||
Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
||||||
|
|
||||||
url := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Front.Port)
|
url := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Front.Port)
|
||||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("%s is available at:", misc.Software)))
|
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("%s is available at:", misc.Software)))
|
||||||
|
|
||||||
if !config.Config.HeadlessMode {
|
if !config.Config.HeadlessMode {
|
||||||
|
@@ -56,7 +56,7 @@ func tap() {
|
|||||||
Str("limit", config.Config.Tap.StorageLimit).
|
Str("limit", config.Config.Tap.StorageLimit).
|
||||||
Msg(fmt.Sprintf("%s will store the traffic up to a limit (per node). Oldest TCP/UDP streams will be removed once the limit is reached.", misc.Software))
|
Msg(fmt.Sprintf("%s will store the traffic up to a limit (per node). Oldest TCP/UDP streams will be removed once the limit is reached.", misc.Software))
|
||||||
|
|
||||||
connector = connect.NewConnector(kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
connector = connect.NewConnector(kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port), connect.DefaultRetries, connect.DefaultTimeout)
|
||||||
|
|
||||||
kubernetesProvider, err := getKubernetesProviderForCli(false, false)
|
kubernetesProvider, err := getKubernetesProviderForCli(false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -434,7 +434,7 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
|
|||||||
|
|
||||||
if !update && !config.Config.Tap.Ingress.Enabled {
|
if !update && !config.Config.Tap.Ingress.Enabled {
|
||||||
// Hub proxy URL
|
// Hub proxy URL
|
||||||
url := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.Port)
|
url := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Hub.Port)
|
||||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ func postFrontStarted(ctx context.Context, kubernetesProvider *kubernetes.Provid
|
|||||||
if config.Config.Tap.Ingress.Enabled {
|
if config.Config.Tap.Ingress.Enabled {
|
||||||
url = fmt.Sprintf("http://%s", config.Config.Tap.Ingress.Host)
|
url = fmt.Sprintf("http://%s", config.Config.Tap.Ingress.Host)
|
||||||
} else {
|
} else {
|
||||||
url = kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Front.Port)
|
url = kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Front.Port)
|
||||||
}
|
}
|
||||||
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("%s is available at:", misc.Software)))
|
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("%s is available at:", misc.Software)))
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kubeshark/kubeshark/config"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"k8s.io/apimachinery/pkg/util/httpstream"
|
"k8s.io/apimachinery/pkg/util/httpstream"
|
||||||
"k8s.io/client-go/tools/portforward"
|
"k8s.io/client-go/tools/portforward"
|
||||||
@@ -66,8 +67,8 @@ func getSelfHubProxiedHostAndPath(selfNamespace string, selfServiceName string)
|
|||||||
return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy", selfNamespace, selfServiceName, selfServicePort)
|
return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy", selfNamespace, selfServiceName, selfServicePort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLocalhostOnPort(port uint16) string {
|
func GetProxyOnPort(port uint16) string {
|
||||||
return fmt.Sprintf("http://localhost:%d", port)
|
return fmt.Sprintf("http://%s:%d", config.Config.Tap.Proxy.Host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRerouteHttpHandlerSelfAPI(proxyHandler http.Handler, selfNamespace string, selfServiceName string) http.Handler {
|
func getRerouteHttpHandlerSelfAPI(proxyHandler http.Handler, selfNamespace string, selfServiceName string) http.Handler {
|
||||||
|
Reference in New Issue
Block a user