added k8s server version check (#404)

This commit is contained in:
RoyUP9
2021-10-27 09:35:30 +03:00
committed by GitHub
parent e9e16551ad
commit fbee4454e4
2 changed files with 33 additions and 11 deletions

View File

@@ -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
}

View File

@@ -25,6 +25,7 @@ const (
TapperDaemonSetName = MizuResourcesPrefix + "tapper-daemon-set"
TapperPodName = MizuResourcesPrefix + "tapper"
ConfigMapName = MizuResourcesPrefix + "policy"
MinKubernetesServerVersion = "1.16.0"
)
func GetMizuFolderPath() string {