diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index ca26718f0..3b1bc9773 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/up9inc/mizu/shared/semver" "k8s.io/apimachinery/pkg/version" "net/url" "path/filepath" @@ -83,6 +84,10 @@ func NewProvider(kubeConfigPath string) (*Provider, error) { return nil, err } + if err := validateKubernetesVersion(clientSet); err != nil { + return nil, err + } + return &Provider{ clientSet: clientSet, kubernetesConfig: kubernetesConfig, @@ -761,3 +766,19 @@ func validateNotProxy(kubernetesConfig clientcmd.ClientConfig, restClientConfig return nil } + +func validateKubernetesVersion(clientSet *kubernetes.Clientset) error { + serverVersion, err := clientSet.ServerVersion() + if err != nil { + logger.Log.Debugf("error while getting kubernetes server version, err: %v", err) + return nil + } + + serverVersionSemVer := semver.SemVersion(serverVersion.GitVersion) + minKubernetesServerVersionSemVer := semver.SemVersion(mizu.MinKubernetesServerVersion) + if minKubernetesServerVersionSemVer.GreaterThan(serverVersionSemVer) { + return fmt.Errorf("kubernetes server version %v is not supported, supporting only kubernetes server version of %v or higher", serverVersion.GitVersion, mizu.MinKubernetesServerVersion) + } + + return nil +} diff --git a/cli/mizu/consts.go b/cli/mizu/consts.go index c90c78179..a25e6733b 100644 --- a/cli/mizu/consts.go +++ b/cli/mizu/consts.go @@ -14,17 +14,18 @@ var ( ) const ( - MizuResourcesPrefix = "mizu-" - ApiServerPodName = MizuResourcesPrefix + "api-server" - ClusterRoleBindingName = MizuResourcesPrefix + "cluster-role-binding" - ClusterRoleName = MizuResourcesPrefix + "cluster-role" - K8sAllNamespaces = "" - RoleBindingName = MizuResourcesPrefix + "role-binding" - RoleName = MizuResourcesPrefix + "role" - ServiceAccountName = MizuResourcesPrefix + "service-account" - TapperDaemonSetName = MizuResourcesPrefix + "tapper-daemon-set" - TapperPodName = MizuResourcesPrefix + "tapper" - ConfigMapName = MizuResourcesPrefix + "policy" + MizuResourcesPrefix = "mizu-" + ApiServerPodName = MizuResourcesPrefix + "api-server" + ClusterRoleBindingName = MizuResourcesPrefix + "cluster-role-binding" + ClusterRoleName = MizuResourcesPrefix + "cluster-role" + K8sAllNamespaces = "" + RoleBindingName = MizuResourcesPrefix + "role-binding" + RoleName = MizuResourcesPrefix + "role" + ServiceAccountName = MizuResourcesPrefix + "service-account" + TapperDaemonSetName = MizuResourcesPrefix + "tapper-daemon-set" + TapperPodName = MizuResourcesPrefix + "tapper" + ConfigMapName = MizuResourcesPrefix + "policy" + MinKubernetesServerVersion = "1.16.0" ) func GetMizuFolderPath() string {