1
0
mirror of https://github.com/rancher/rke.git synced 2025-07-04 11:07:43 +00:00

honor kubernetes_version setting

This commit is contained in:
Jason Greathouse 2019-01-24 13:20:22 -06:00 committed by Alena Prokharchyk
parent dad34d4da2
commit a64e8f64fb
4 changed files with 78 additions and 7 deletions

View File

@ -168,7 +168,10 @@ func InitClusterObject(ctx context.Context, rkeConfig *v3.RancherKubernetesEngin
} }
// Setting cluster Defaults // Setting cluster Defaults
c.setClusterDefaults(ctx) err := c.setClusterDefaults(ctx)
if err != nil {
return nil, err
}
// extract cluster network configuration // extract cluster network configuration
c.setNetworkOptions() c.setNetworkOptions()

View File

@ -11,6 +11,7 @@ import (
"github.com/rancher/rke/log" "github.com/rancher/rke/log"
"github.com/rancher/rke/services" "github.com/rancher/rke/services"
"github.com/rancher/rke/templates" "github.com/rancher/rke/templates"
"github.com/rancher/rke/util"
"github.com/rancher/types/apis/management.cattle.io/v3" "github.com/rancher/types/apis/management.cattle.io/v3"
) )
@ -75,7 +76,7 @@ func setDefaultIfEmpty(varName *string, defaultValue string) {
} }
} }
func (c *Cluster) setClusterDefaults(ctx context.Context) { func (c *Cluster) setClusterDefaults(ctx context.Context) error {
if len(c.SSHKeyPath) == 0 { if len(c.SSHKeyPath) == 0 {
c.SSHKeyPath = DefaultClusterSSHKeyPath c.SSHKeyPath = DefaultClusterSSHKeyPath
} }
@ -144,10 +145,15 @@ func (c *Cluster) setClusterDefaults(ctx context.Context) {
} }
c.PrivateRegistriesMap[pr.URL] = pr c.PrivateRegistriesMap[pr.URL] = pr
} }
c.setClusterImageDefaults() err := c.setClusterImageDefaults()
if err != nil {
return err
}
c.setClusterServicesDefaults() c.setClusterServicesDefaults()
c.setClusterNetworkDefaults() c.setClusterNetworkDefaults()
c.setClusterAuthnDefaults() c.setClusterAuthnDefaults()
return nil
} }
func (c *Cluster) setClusterServicesDefaults() { func (c *Cluster) setClusterServicesDefaults() {
@ -200,13 +206,17 @@ func (c *Cluster) setClusterServicesDefaults() {
} }
} }
func (c *Cluster) setClusterImageDefaults() { func (c *Cluster) setClusterImageDefaults() error {
var privRegURL string var privRegURL string
imageDefaults, ok := v3.K8sVersionToRKESystemImages[c.Version]
if !ok { // Version Check
imageDefaults = v3.K8sVersionToRKESystemImages[DefaultK8sVersion] err := util.ValidateVersion(c.Version)
if err != nil {
return err
} }
imageDefaults := v3.AllK8sVersions[c.Version]
for _, privReg := range c.PrivateRegistries { for _, privReg := range c.PrivateRegistries {
if privReg.IsDefault { if privReg.IsDefault {
privRegURL = privReg.URL privRegURL = privReg.URL
@ -243,6 +253,8 @@ func (c *Cluster) setClusterImageDefaults() {
for k, v := range systemImagesDefaultsMap { for k, v := range systemImagesDefaultsMap {
setDefaultIfEmpty(k, v) setDefaultIfEmpty(k, v)
} }
return nil
} }
func (c *Cluster) setClusterNetworkDefaults() { func (c *Cluster) setClusterNetworkDefaults() {

View File

@ -12,6 +12,7 @@ import (
"github.com/rancher/rke/cluster" "github.com/rancher/rke/cluster"
"github.com/rancher/rke/pki" "github.com/rancher/rke/pki"
"github.com/rancher/rke/services" "github.com/rancher/rke/services"
"github.com/rancher/rke/util"
"github.com/rancher/types/apis/management.cattle.io/v3" "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -402,11 +403,21 @@ func getAddonManifests(reader *bufio.Reader) ([]string, error) {
func generateSystemImagesList(version string, all bool) error { func generateSystemImagesList(version string, all bool) error {
allVersions := []string{} allVersions := []string{}
for version := range v3.AllK8sVersions { for version := range v3.AllK8sVersions {
err := util.ValidateVersion(version)
if err != nil {
continue
}
allVersions = append(allVersions, version) allVersions = append(allVersions, version)
} }
if all { if all {
for version, rkeSystemImages := range v3.AllK8sVersions { for version, rkeSystemImages := range v3.AllK8sVersions {
err := util.ValidateVersion(version)
if err != nil {
continue
}
logrus.Infof("Generating images list for version [%s]:", version) logrus.Infof("Generating images list for version [%s]:", version)
uniqueImages := getUniqueSystemImageList(rkeSystemImages) uniqueImages := getUniqueSystemImageList(rkeSystemImages)
for _, image := range uniqueImages { for _, image := range uniqueImages {

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"github.com/coreos/go-semver/semver" "github.com/coreos/go-semver/semver"
"github.com/rancher/types/apis/management.cattle.io/v3"
) )
const ( const (
@ -63,3 +64,47 @@ func IsSymlink(file string) (bool, error) {
} }
return false, nil 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
}