mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-08-20 12:56:59 +00:00
golangci-lint-action@v3 pins `latest` to v1.64.8, which is built with go1.24 and refuses to run now that go.mod targets 1.25.0: can't load config: the Go language version (go1.24) used to build golangci-lint is lower than the targeted Go version (1.25.0) Move the job to golangci-lint-action@v7 + v2.8.0 and add a .golangci.yml mirroring the hub repo's v2 config: govet, staticcheck, ineffassign and unused, plus gofmt/goimports as formatters. Fixes for the issues that surfaced: - ST1005: lowercase error strings, drop trailing '!' in connect/hub.go - SA4011: kubernetes/watch.go had a `break` inside a `select` default that broke the select rather than the loop, i.e. a no-op; removed - QF1008: drop the embedded ChartPathOptions selector in helm.go - QF1003: tagged switch on r.URL.Path in mcp_test.go - QF1004: strings.Replace(..., -1) -> strings.ReplaceAll - gofmt -s and goimports with a local prefix across the tree errcheck is not in the enabled set, matching hub.
109 lines
2.8 KiB
Go
109 lines
2.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/kubeshark/kubeshark/config"
|
|
"github.com/kubeshark/kubeshark/config/configStructs"
|
|
"github.com/kubeshark/kubeshark/internal/connect"
|
|
"github.com/kubeshark/kubeshark/kubernetes"
|
|
"github.com/kubeshark/kubeshark/misc"
|
|
"github.com/kubeshark/kubeshark/utils"
|
|
)
|
|
|
|
func runProxy(block bool, noBrowser bool) {
|
|
kubernetesProvider, err := getKubernetesProviderForCli(false, false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
exists, err := kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.Release.Namespace, kubernetes.FrontServiceName)
|
|
if err != nil {
|
|
log.Error().
|
|
Str("service", kubernetes.FrontServiceName).
|
|
Err(err).
|
|
Msg("Failed to found service!")
|
|
cancel()
|
|
return
|
|
}
|
|
|
|
if !exists {
|
|
log.Error().
|
|
Str("service", kubernetes.FrontServiceName).
|
|
Str("command", fmt.Sprintf("%s %s", misc.Program, tapCmd.Use)).
|
|
Msg("Service not found! You should run the command first:")
|
|
cancel()
|
|
return
|
|
}
|
|
|
|
exists, err = kubernetesProvider.DoesServiceExist(ctx, config.Config.Tap.Release.Namespace, kubernetes.HubServiceName)
|
|
if err != nil {
|
|
log.Error().
|
|
Str("service", kubernetes.HubServiceName).
|
|
Err(err).
|
|
Msg("Failed to found service!")
|
|
cancel()
|
|
return
|
|
}
|
|
|
|
if !exists {
|
|
log.Error().
|
|
Str("service", kubernetes.HubServiceName).
|
|
Str("command", fmt.Sprintf("%s %s", misc.Program, tapCmd.Use)).
|
|
Msg("Service not found! You should run the command first:")
|
|
cancel()
|
|
return
|
|
}
|
|
|
|
var establishedProxy bool
|
|
|
|
frontUrl := kubernetes.GetProxyOnPort(config.Config.Tap.Proxy.Front.Port)
|
|
response, err := http.Get(fmt.Sprintf("%s/", frontUrl))
|
|
if err == nil && response.StatusCode == 200 {
|
|
log.Info().
|
|
Str("service", kubernetes.FrontServiceName).
|
|
Int("port", int(config.Config.Tap.Proxy.Front.Port)).
|
|
Msg("Found a running service.")
|
|
|
|
okToOpen("Kubeshark", frontUrl, noBrowser)
|
|
} else {
|
|
startProxyReportErrorIfAny(
|
|
kubernetesProvider,
|
|
ctx,
|
|
kubernetes.FrontServiceName,
|
|
kubernetes.FrontPodName,
|
|
configStructs.ProxyFrontPortLabel,
|
|
config.Config.Tap.Proxy.Front.Port,
|
|
configStructs.ContainerPort,
|
|
"",
|
|
)
|
|
connector := connect.NewConnector(frontUrl, connect.DefaultRetries, connect.DefaultTimeout)
|
|
if err := connector.TestConnection(""); err != nil {
|
|
log.Error().Msg(fmt.Sprintf(utils.Red, "Couldn't connect to Front."))
|
|
return
|
|
}
|
|
|
|
establishedProxy = true
|
|
okToOpen("Kubeshark", frontUrl, noBrowser)
|
|
}
|
|
if establishedProxy && block {
|
|
utils.WaitForTermination(ctx, cancel)
|
|
}
|
|
|
|
}
|
|
|
|
func okToOpen(name string, url string, noBrowser bool) {
|
|
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, fmt.Sprintf("%s is available at:", name)))
|
|
|
|
if !config.Config.HeadlessMode && !noBrowser {
|
|
utils.OpenBrowser(url)
|
|
}
|
|
}
|