diff --git a/cmd/kubeadm/app/constants/constants.go b/cmd/kubeadm/app/constants/constants.go index fee98ece17c..02b0d615c71 100644 --- a/cmd/kubeadm/app/constants/constants.go +++ b/cmd/kubeadm/app/constants/constants.go @@ -496,16 +496,27 @@ var ( // CurrentKubernetesVersion specifies current Kubernetes version supported by kubeadm CurrentKubernetesVersion = getSkewedKubernetesVersion(0) - // SupportedEtcdVersion lists officially supported etcd versions with corresponding Kubernetes releases + // SupportedEtcdVersion lists officially supported etcd versions with corresponding + // Kubernetes releases. + // // If you are updating the versions in this map, make sure to also update: // - MinExternalEtcdVersion: with the minimum etcd version from this map. - // - DefaultEtcdVersion: with etcd version used for the current k8s release (0). - // The maximum length of the map should be 2, as kubeadm supports a maximum skew of -1 - // with the control plane version. + // - DefaultEtcdVersion: with etcd version used for the current k8s release. + // + // The maximum length of the map should be 3. kubeadm supports a maximum skew of -1 + // with the control plane version, but before a release the oldest k8s version in this + // map will be the only stable version, thus one additional version is required + // to be unit tested. + // + // This map should not be used directly in kubeadm code. Instead, it should be used with + // EtcdSupportedVersion(), as it allows for returning a valid version even if the input + // k8s version key is not defined (out of bounds). This allows for kubeadm to assume + // an etcd version even if the map is not yet updated before a release. The user will + // get a warning in that case, so ideally the map should be updated for each release. SupportedEtcdVersion = map[uint8]string{ - uint8(getSkewedKubernetesVersion(-2).Minor()): "3.5.24-0", - uint8(getSkewedKubernetesVersion(-1).Minor()): "3.6.6-0", - uint8(getSkewedKubernetesVersion(0).Minor()): "3.6.6-0", + 34: "3.6.6-0", + 35: "3.6.6-0", + 36: "3.6.6-0", } // KubeadmCertsClusterRoleName sets the name for the ClusterRole that allows diff --git a/cmd/kubeadm/app/constants/constants_test.go b/cmd/kubeadm/app/constants/constants_test.go index dea843890e1..ebd95631cff 100644 --- a/cmd/kubeadm/app/constants/constants_test.go +++ b/cmd/kubeadm/app/constants/constants_test.go @@ -98,10 +98,18 @@ func TestGetStaticPodFilepath(t *testing.T) { } } +func TestEtcdSupportedVersionLength(t *testing.T) { + const max = 3 + if len(SupportedEtcdVersion) != max { + t.Fatalf("SupportedEtcdVersion must include exactly %d versions", max) + } +} + func TestEtcdSupportedVersion(t *testing.T) { var supportedEtcdVersion = map[uint8]string{ 17: "3.3.17-0", - 18: "3.4.3-0", + 18: "3.4.2-0", + 19: "3.4.3-0", } var tests = []struct { kubernetesVersion string @@ -135,7 +143,7 @@ func TestEtcdSupportedVersion(t *testing.T) { }, { kubernetesVersion: "1.18.1", - expectedVersion: version.MustParseSemantic("3.4.3-0"), + expectedVersion: version.MustParseSemantic("3.4.2-0"), expectedWarning: false, expectedError: false, },