diff --git a/cluster/addons.go b/cluster/addons.go index d0ef626c..be4c618f 100644 --- a/cluster/addons.go +++ b/cluster/addons.go @@ -15,6 +15,7 @@ import ( "github.com/rancher/rke/addons" "github.com/rancher/rke/k8s" "github.com/rancher/rke/log" + "github.com/rancher/rke/util" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) @@ -291,7 +292,7 @@ func (c *Cluster) deployMetricServer(ctx context.Context) error { MetricsServerImage: c.SystemImages.MetricsServer, RBACConfig: c.Authorization.Mode, Options: c.Monitoring.Options, - Version: getTagMajorVersion(versionTag), + Version: util.GetTagMajorVersion(versionTag), } metricsYaml, err := addons.GetMetricsServerManifest(MetricsServerConfig) if err != nil { diff --git a/cluster/network.go b/cluster/network.go index 622c0938..dbf4b62d 100644 --- a/cluster/network.go +++ b/cluster/network.go @@ -142,7 +142,7 @@ func (c *Cluster) doFlannelDeploy(ctx context.Context) error { "Type": c.Network.Options[FlannelBackendType], }, RBACConfig: c.Authorization.Mode, - ClusterVersion: getTagMajorVersion(c.Version), + ClusterVersion: util.GetTagMajorVersion(c.Version), } pluginYaml, err := c.getNetworkPluginManifest(flannelConfig) if err != nil { diff --git a/cluster/plan.go b/cluster/plan.go index 6154d244..76f44450 100644 --- a/cluster/plan.go +++ b/cluster/plan.go @@ -185,7 +185,7 @@ func (c *Cluster) BuildKubeAPIProcess(host *hosts.Host, prefixPath string) v3.Pr } } // 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)) } @@ -803,11 +803,11 @@ func BuildPortChecksFromPortList(host *hosts.Host, portList []string, proto stri } func (c *Cluster) GetKubernetesServicesOptions() v3.KubernetesServicesOptions { - clusterMajorVersion := getTagMajorVersion(c.Version) + clusterMajorVersion := util.GetTagMajorVersion(c.Version) NamedkK8sImage, _ := ref.ParseNormalizedNamed(c.SystemImages.Kubernetes) k8sImageTag := NamedkK8sImage.(ref.Tagged).Tag() - k8sImageMajorVersion := getTagMajorVersion(k8sImageTag) + k8sImageMajorVersion := util.GetTagMajorVersion(k8sImageTag) if clusterMajorVersion != k8sImageMajorVersion && k8sImageMajorVersion != "" { clusterMajorVersion = k8sImageMajorVersion @@ -820,14 +820,6 @@ func (c *Cluster) GetKubernetesServicesOptions() 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 { configByteSum := md5.Sum([]byte(config)) return fmt.Sprintf("%x", configByteSum) diff --git a/templates/templates.go b/templates/templates.go index a13d457c..25966f4c 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -3,16 +3,18 @@ package templates import ( "bytes" "text/template" + + "github.com/rancher/rke/util" ) var VersionedTemplate = map[string]map[string]string{ "calico": map[string]string{ - "v1.13.1-rancher1-1": CalicoTemplateV113, - "default": CalicoTemplateV112, + "v1.13": CalicoTemplateV113, + "default": CalicoTemplateV112, }, "canal": map[string]string{ - "v1.13.1-rancher1-1": CanalTemplateV113, - "default": CanalTemplateV112, + "v1.13": CanalTemplateV113, + "default": CanalTemplateV112, }, } @@ -26,9 +28,10 @@ func CompileTemplateFromMap(tmplt string, configMap interface{}) (string, error) } func GetVersionedTemplates(templateName string, k8sVersion string) string { + versionedTemplate := VersionedTemplate[templateName] - if _, ok := versionedTemplate[k8sVersion]; ok { - return versionedTemplate[k8sVersion] + if t, ok := versionedTemplate[util.GetTagMajorVersion(k8sVersion)]; ok { + return t } return versionedTemplate["default"] } diff --git a/util/util.go b/util/util.go index 0971ee09..4bdb65bd 100644 --- a/util/util.go +++ b/util/util.go @@ -133,3 +133,11 @@ func IsRancherBackupSupported(image string) bool { } return true } + +func GetTagMajorVersion(tag string) string { + splitTag := strings.Split(tag, ".") + if len(splitTag) < 2 { + return "" + } + return strings.Join(splitTag[:2], ".") +}