mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-29 05:43:58 +00:00
added alert and error when there is a proxy before k8b server (#402)
This commit is contained in:
parent
e696851261
commit
779257b864
@ -14,6 +14,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
MizuResourcesNamespaceConfigName = "mizu-resources-namespace"
|
MizuResourcesNamespaceConfigName = "mizu-resources-namespace"
|
||||||
ConfigFilePathCommandName = "config-path"
|
ConfigFilePathCommandName = "config-path"
|
||||||
|
KubeConfigPathConfigName = "kube-config-path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigStruct struct {
|
type ConfigStruct struct {
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"k8s.io/apimachinery/pkg/version"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -77,6 +79,10 @@ func NewProvider(kubeConfigPath string) (*Provider, error) {
|
|||||||
"you can set alternative kube config file path by adding the kube-config-path field to the mizu config file, err: %w", kubeConfigPath, err)
|
"you can set alternative kube config file path by adding the kube-config-path field to the mizu config file, err: %w", kubeConfigPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := validateNotProxy(kubernetesConfig, restClientConfig); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &Provider{
|
return &Provider{
|
||||||
clientSet: clientSet,
|
clientSet: clientSet,
|
||||||
kubernetesConfig: kubernetesConfig,
|
kubernetesConfig: kubernetesConfig,
|
||||||
@ -727,3 +733,31 @@ func loadKubernetesConfiguration(kubeConfigPath string) clientcmd.ClientConfig {
|
|||||||
func isPodRunning(pod *core.Pod) bool {
|
func isPodRunning(pod *core.Pod) bool {
|
||||||
return pod.Status.Phase == core.PodRunning
|
return pod.Status.Phase == core.PodRunning
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We added this after a customer tried to run mizu from lens, which used len's kube config, which have cluster server configuration, which points to len's local proxy.
|
||||||
|
// The workaround was to use the user's local default kube config.
|
||||||
|
// For now - we are blocking the option to run mizu through a proxy to k8s server
|
||||||
|
func validateNotProxy(kubernetesConfig clientcmd.ClientConfig, restClientConfig *restclient.Config) error {
|
||||||
|
kubernetesUrl, err := url.Parse(restClientConfig.Host)
|
||||||
|
if err != nil {
|
||||||
|
logger.Log.Debugf("validateNotProxy - error while parsing kubernetes host, err: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
restProxyClientConfig, _ := kubernetesConfig.ClientConfig()
|
||||||
|
restProxyClientConfig.Host = kubernetesUrl.Host
|
||||||
|
|
||||||
|
clientProxySet, err := getClientSet(restProxyClientConfig)
|
||||||
|
if err == nil {
|
||||||
|
proxyServerVersion, err := clientProxySet.ServerVersion()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if *proxyServerVersion == (version.Info{}) {
|
||||||
|
return fmt.Errorf("cannot establish http-proxy connection to the Kubernetes cluster. If you’re using Lens or similar tool, please run mizu with regular kubectl config using --%v %v=$HOME/.kube/config flag", config.SetCommandName, config.KubeConfigPathConfigName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user