1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-28 03:31:24 +00:00

Fix versioned templates version check

This commit is contained in:
moelsayed 2019-02-27 01:14:01 +02:00 committed by Alena Prokharchyk
parent 2fa825f3fe
commit eb6116dded
5 changed files with 23 additions and 19 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/rancher/rke/addons" "github.com/rancher/rke/addons"
"github.com/rancher/rke/k8s" "github.com/rancher/rke/k8s"
"github.com/rancher/rke/log" "github.com/rancher/rke/log"
"github.com/rancher/rke/util"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -291,7 +292,7 @@ func (c *Cluster) deployMetricServer(ctx context.Context) error {
MetricsServerImage: c.SystemImages.MetricsServer, MetricsServerImage: c.SystemImages.MetricsServer,
RBACConfig: c.Authorization.Mode, RBACConfig: c.Authorization.Mode,
Options: c.Monitoring.Options, Options: c.Monitoring.Options,
Version: getTagMajorVersion(versionTag), Version: util.GetTagMajorVersion(versionTag),
} }
metricsYaml, err := addons.GetMetricsServerManifest(MetricsServerConfig) metricsYaml, err := addons.GetMetricsServerManifest(MetricsServerConfig)
if err != nil { if err != nil {

View File

@ -142,7 +142,7 @@ func (c *Cluster) doFlannelDeploy(ctx context.Context) error {
"Type": c.Network.Options[FlannelBackendType], "Type": c.Network.Options[FlannelBackendType],
}, },
RBACConfig: c.Authorization.Mode, RBACConfig: c.Authorization.Mode,
ClusterVersion: getTagMajorVersion(c.Version), ClusterVersion: util.GetTagMajorVersion(c.Version),
} }
pluginYaml, err := c.getNetworkPluginManifest(flannelConfig) pluginYaml, err := c.getNetworkPluginManifest(flannelConfig)
if err != nil { if err != nil {

View File

@ -185,7 +185,7 @@ func (c *Cluster) BuildKubeAPIProcess(host *hosts.Host, prefixPath string) v3.Pr
} }
} }
// check api server count for k8s v1.8 // check api server count for k8s v1.8
if getTagMajorVersion(c.Version) == "v1.8" { if util.GetTagMajorVersion(c.Version) == "v1.8" {
CommandArgs["apiserver-count"] = strconv.Itoa(len(c.ControlPlaneHosts)) CommandArgs["apiserver-count"] = strconv.Itoa(len(c.ControlPlaneHosts))
} }
@ -803,11 +803,11 @@ func BuildPortChecksFromPortList(host *hosts.Host, portList []string, proto stri
} }
func (c *Cluster) GetKubernetesServicesOptions() v3.KubernetesServicesOptions { func (c *Cluster) GetKubernetesServicesOptions() v3.KubernetesServicesOptions {
clusterMajorVersion := getTagMajorVersion(c.Version) clusterMajorVersion := util.GetTagMajorVersion(c.Version)
NamedkK8sImage, _ := ref.ParseNormalizedNamed(c.SystemImages.Kubernetes) NamedkK8sImage, _ := ref.ParseNormalizedNamed(c.SystemImages.Kubernetes)
k8sImageTag := NamedkK8sImage.(ref.Tagged).Tag() k8sImageTag := NamedkK8sImage.(ref.Tagged).Tag()
k8sImageMajorVersion := getTagMajorVersion(k8sImageTag) k8sImageMajorVersion := util.GetTagMajorVersion(k8sImageTag)
if clusterMajorVersion != k8sImageMajorVersion && k8sImageMajorVersion != "" { if clusterMajorVersion != k8sImageMajorVersion && k8sImageMajorVersion != "" {
clusterMajorVersion = k8sImageMajorVersion clusterMajorVersion = k8sImageMajorVersion
@ -820,14 +820,6 @@ func (c *Cluster) GetKubernetesServicesOptions() v3.KubernetesServicesOptions {
return v3.KubernetesServicesOptions{} return v3.KubernetesServicesOptions{}
} }
func getTagMajorVersion(tag string) string {
splitTag := strings.Split(tag, ".")
if len(splitTag) < 2 {
return ""
}
return strings.Join(splitTag[:2], ".")
}
func getCloudConfigChecksum(config string) string { func getCloudConfigChecksum(config string) string {
configByteSum := md5.Sum([]byte(config)) configByteSum := md5.Sum([]byte(config))
return fmt.Sprintf("%x", configByteSum) return fmt.Sprintf("%x", configByteSum)

View File

@ -3,16 +3,18 @@ package templates
import ( import (
"bytes" "bytes"
"text/template" "text/template"
"github.com/rancher/rke/util"
) )
var VersionedTemplate = map[string]map[string]string{ var VersionedTemplate = map[string]map[string]string{
"calico": map[string]string{ "calico": map[string]string{
"v1.13.1-rancher1-1": CalicoTemplateV113, "v1.13": CalicoTemplateV113,
"default": CalicoTemplateV112, "default": CalicoTemplateV112,
}, },
"canal": map[string]string{ "canal": map[string]string{
"v1.13.1-rancher1-1": CanalTemplateV113, "v1.13": CanalTemplateV113,
"default": CanalTemplateV112, "default": CanalTemplateV112,
}, },
} }
@ -26,9 +28,10 @@ func CompileTemplateFromMap(tmplt string, configMap interface{}) (string, error)
} }
func GetVersionedTemplates(templateName string, k8sVersion string) string { func GetVersionedTemplates(templateName string, k8sVersion string) string {
versionedTemplate := VersionedTemplate[templateName] versionedTemplate := VersionedTemplate[templateName]
if _, ok := versionedTemplate[k8sVersion]; ok { if t, ok := versionedTemplate[util.GetTagMajorVersion(k8sVersion)]; ok {
return versionedTemplate[k8sVersion] return t
} }
return versionedTemplate["default"] return versionedTemplate["default"]
} }

View File

@ -133,3 +133,11 @@ func IsRancherBackupSupported(image string) bool {
} }
return true return true
} }
func GetTagMajorVersion(tag string) string {
splitTag := strings.Split(tag, ".")
if len(splitTag) < 2 {
return ""
}
return strings.Join(splitTag[:2], ".")
}