kubeadm: revert to using a static list of etcd versions

The introduction of dynamic keys in the etcd version
map in constants.go introduced a couple of problems:

1. The size of the map could no longer be unit tested
because at UT runtime there was only one key "0".

2. Once a new k8s release branch is cut the version map
has mismatched versions. The latest k8s version mapped to the
future prerelease alpha (placeholder), the previous was the current
WIP release version and the oldest version in the map is the
current stable. This introduces a undesider shift of versions
where we are applying the wrong version to the current WIP
release unless an contrubutor PRs it.

The old static approach on the other hand is safer because
it hardcodes the versions, and the utility function
EtcdSupportedVersion() ensures that we get a relevant etcd
version even if the input k8s MINOR key is out of bonds for the map.

- Revert to using static version in the map.
- Revert the unit test TestEtcdSupportedVersionLength.
- Add additional comments over the map.
This commit is contained in:
Lubomir I. Ivanov
2025-12-08 13:40:11 +01:00
parent 03e14cc943
commit 05c4e3febe
2 changed files with 28 additions and 9 deletions

View File

@@ -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

View File

@@ -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,
},