From bf4cb96e0f04ae0eab2756846d9f23cc8a45df06 Mon Sep 17 00:00:00 2001 From: SataQiu Date: Fri, 8 Jul 2022 19:18:06 +0800 Subject: [PATCH] kubeadm: fix the bug that configurable KubernetesVersion not respected during kubeadm join --- cmd/kubeadm/app/componentconfigs/kubelet.go | 5 ++++- cmd/kubeadm/app/constants/constants.go | 3 +++ cmd/kubeadm/app/util/config/common.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/kubeadm/app/componentconfigs/kubelet.go b/cmd/kubeadm/app/componentconfigs/kubelet.go index bc230df45e9..2509ac30618 100644 --- a/cmd/kubeadm/app/componentconfigs/kubelet.go +++ b/cmd/kubeadm/app/componentconfigs/kubelet.go @@ -74,8 +74,11 @@ var kubeletHandler = handler{ } func kubeletConfigFromCluster(h *handler, clientset clientset.Interface, clusterCfg *kubeadmapi.ClusterConfiguration) (kubeadmapi.ComponentConfig, error) { + // Resolve possible CI version labels + ver := strings.TrimPrefix(clusterCfg.KubernetesVersion, constants.CIKubernetesVersionPrefix) + // Read the ConfigMap from the cluster based on what version the kubelet is - k8sVersion, err := version.ParseGeneric(clusterCfg.KubernetesVersion) + k8sVersion, err := version.ParseGeneric(ver) if err != nil { return nil, err } diff --git a/cmd/kubeadm/app/constants/constants.go b/cmd/kubeadm/app/constants/constants.go index c2b8f6e64be..b1e7164854b 100644 --- a/cmd/kubeadm/app/constants/constants.go +++ b/cmd/kubeadm/app/constants/constants.go @@ -355,6 +355,9 @@ const ( // TODO: Find a better place for this constant YAMLDocumentSeparator = "---\n" + // CIKubernetesVersionPrefix is the prefix for CI Kubernetes version + CIKubernetesVersionPrefix = "ci/" + // DefaultAPIServerBindAddress is the default bind address for the API Server DefaultAPIServerBindAddress = "0.0.0.0" diff --git a/cmd/kubeadm/app/util/config/common.go b/cmd/kubeadm/app/util/config/common.go index 9fddc4c19a2..7a5911bf93a 100644 --- a/cmd/kubeadm/app/util/config/common.go +++ b/cmd/kubeadm/app/util/config/common.go @@ -104,7 +104,7 @@ func NormalizeKubernetesVersion(cfg *kubeadmapi.ClusterConfiguration) error { // Requested version is automatic CI build, thus mark CIKubernetesVersion as `ci/` if isCIVersion { - cfg.CIKubernetesVersion = fmt.Sprintf("ci/%s", ver) + cfg.CIKubernetesVersion = fmt.Sprintf("%s%s", constants.CIKubernetesVersionPrefix, ver) } cfg.KubernetesVersion = ver