diff --git a/cli/config/configStruct.go b/cli/config/configStruct.go index 50e1049a7..171ed11d0 100644 --- a/cli/config/configStruct.go +++ b/cli/config/configStruct.go @@ -14,6 +14,7 @@ import ( const ( MizuResourcesNamespaceConfigName = "mizu-resources-namespace" ConfigFilePathCommandName = "config-path" + KubeConfigPathConfigName = "kube-config-path" ) type ConfigStruct struct { diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index 4cf36c3ca..ca26718f0 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -7,6 +7,8 @@ import ( "encoding/json" "errors" "fmt" + "k8s.io/apimachinery/pkg/version" + "net/url" "path/filepath" "regexp" "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) } + if err := validateNotProxy(kubernetesConfig, restClientConfig); err != nil { + return nil, err + } + return &Provider{ clientSet: clientSet, kubernetesConfig: kubernetesConfig, @@ -727,3 +733,31 @@ func loadKubernetesConfiguration(kubeConfigPath string) clientcmd.ClientConfig { func isPodRunning(pod *core.Pod) bool { 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 +}