mirror of
https://github.com/rancher/rke.git
synced 2025-09-01 15:06:23 +00:00
honor kubernetes_version setting
This commit is contained in:
committed by
Alena Prokharchyk
parent
dad34d4da2
commit
a64e8f64fb
45
util/util.go
45
util/util.go
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -63,3 +64,47 @@ func IsSymlink(file string) (bool, error) {
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// ValidateVersion - Return error if version is not valid
|
||||
// Is version major.minor >= oldest major.minor supported
|
||||
// Is version in the AllK8sVersions list
|
||||
// Is version not in the "bad" list
|
||||
func ValidateVersion(version string) error {
|
||||
// Create target version and current versions list
|
||||
targetVersion, err := StrToSemVer(version)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s is not valid semver", version)
|
||||
}
|
||||
currentVersionsList := []*semver.Version{}
|
||||
for _, ver := range v3.K8sVersionsCurrent {
|
||||
v, err := StrToSemVer(ver)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s in Current Versions list is not valid semver", ver)
|
||||
}
|
||||
|
||||
currentVersionsList = append(currentVersionsList, v)
|
||||
}
|
||||
|
||||
// Make sure Target version is greater than or equal to oldest major.minor supported.
|
||||
semver.Sort(currentVersionsList)
|
||||
if targetVersion.Major < currentVersionsList[0].Major {
|
||||
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
|
||||
}
|
||||
if targetVersion.Major == currentVersionsList[0].Major {
|
||||
if targetVersion.Minor < currentVersionsList[0].Minor {
|
||||
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
|
||||
}
|
||||
}
|
||||
// Make sure Target version is in the AllK8sVersions list.
|
||||
_, ok := v3.AllK8sVersions[version]
|
||||
if !ok {
|
||||
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
|
||||
}
|
||||
// Make sure Target version is not "bad".
|
||||
_, ok = v3.K8sBadVersions[version]
|
||||
if ok {
|
||||
return fmt.Errorf("%s is an unsupported Kubernetes version - see 'rke config --system-images --all' for versions supported with this release", version)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user