From 6fe91ad9cf9f99401fc39a6ece24eed61f17b0e2 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 10 Apr 2024 15:29:56 +0400 Subject: [PATCH] feat: provide Kubernets/Talos version compatibility for 1.8 Fixes #8572 This allows to use 1.7 machinery with future 1.8 (e.g. alpha) versions. Signed-off-by: Andrey Smirnov --- .../compatibility/kubernetes_version.go | 3 ++ .../compatibility/kubernetes_version_test.go | 33 +++++++++++++ .../compatibility/talos18/talos18.go | 28 +++++++++++ pkg/machinery/compatibility/talos_version.go | 4 ++ .../compatibility/talos_version_test.go | 49 +++++++++++++++++-- 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 pkg/machinery/compatibility/talos18/talos18.go diff --git a/pkg/machinery/compatibility/kubernetes_version.go b/pkg/machinery/compatibility/kubernetes_version.go index b877c1cc92..f5ff140274 100644 --- a/pkg/machinery/compatibility/kubernetes_version.go +++ b/pkg/machinery/compatibility/kubernetes_version.go @@ -16,6 +16,7 @@ import ( "github.com/siderolabs/talos/pkg/machinery/compatibility/talos15" "github.com/siderolabs/talos/pkg/machinery/compatibility/talos16" "github.com/siderolabs/talos/pkg/machinery/compatibility/talos17" + "github.com/siderolabs/talos/pkg/machinery/compatibility/talos18" ) // KubernetesVersion embeds Kubernetes version. @@ -56,6 +57,8 @@ func (v *KubernetesVersion) SupportedWith(target *TalosVersion) error { minK8sVersion, maxK8sVersion = talos16.MinimumKubernetesVersion, talos16.MaximumKubernetesVersion case talos17.MajorMinor: // upgrades to 1.7.x minK8sVersion, maxK8sVersion = talos17.MinimumKubernetesVersion, talos17.MaximumKubernetesVersion + case talos18.MajorMinor: // upgrades to 1.8.x + minK8sVersion, maxK8sVersion = talos18.MinimumKubernetesVersion, talos18.MaximumKubernetesVersion default: return fmt.Errorf("compatibility with version %s is not supported", target.String()) } diff --git a/pkg/machinery/compatibility/kubernetes_version_test.go b/pkg/machinery/compatibility/kubernetes_version_test.go index 0ef202ff05..8aee46f26b 100644 --- a/pkg/machinery/compatibility/kubernetes_version_test.go +++ b/pkg/machinery/compatibility/kubernetes_version_test.go @@ -220,6 +220,39 @@ func TestKubernetesCompatibility17(t *testing.T) { } } +func TestKubernetesCompatibility18(t *testing.T) { + for _, tt := range []kubernetesVersionTest{ + { + kubernetesVersion: "1.27.1", + target: "1.8.0", + }, + { + kubernetesVersion: "1.26.1", + target: "1.8.0", + }, + { + kubernetesVersion: "1.30.3", + target: "1.8.0-beta.0", + }, + { + kubernetesVersion: "1.31.0-rc.0", + target: "1.8.7", + }, + { + kubernetesVersion: "1.32.0-alpha.0", + target: "1.8.0", + expectedError: "version of Kubernetes 1.32.0-alpha.0 is too new to be used with Talos 1.8.0", + }, + { + kubernetesVersion: "1.25.1", + target: "1.8.0", + expectedError: "version of Kubernetes 1.25.1 is too old to be used with Talos 1.8.0", + }, + } { + runKubernetesVersionTest(t, tt) + } +} + func TestKubernetesCompatibilityUnsupported(t *testing.T) { for _, tt := range []kubernetesVersionTest{ { diff --git a/pkg/machinery/compatibility/talos18/talos18.go b/pkg/machinery/compatibility/talos18/talos18.go new file mode 100644 index 0000000000..a7074ac0cc --- /dev/null +++ b/pkg/machinery/compatibility/talos18/talos18.go @@ -0,0 +1,28 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Package talos18 provides compatibility constants for Talos 1.8. +package talos18 + +import ( + "github.com/blang/semver/v4" +) + +// MajorMinor is the major.minor version of Talos 1.8. +var MajorMinor = [2]uint64{1, 8} + +// MinimumHostUpgradeVersion is the minimum version of Talos that can be upgraded to 1.8. +var MinimumHostUpgradeVersion = semver.MustParse("1.5.0") + +// MaximumHostDowngradeVersion is the maximum (not inclusive) version of Talos that can be downgraded to 1.8. +var MaximumHostDowngradeVersion = semver.MustParse("1.10.0") + +// DeniedHostUpgradeVersions are the versions of Talos that cannot be upgraded to 1.8. +var DeniedHostUpgradeVersions = []semver.Version{} + +// MinimumKubernetesVersion is the minimum version of Kubernetes is supported with 1.8. +var MinimumKubernetesVersion = semver.MustParse("1.26.0") + +// MaximumKubernetesVersion is the maximum version of Kubernetes is supported with 1.8. +var MaximumKubernetesVersion = semver.MustParse("1.31.99") diff --git a/pkg/machinery/compatibility/talos_version.go b/pkg/machinery/compatibility/talos_version.go index 6b94d72fab..cfa80abab0 100644 --- a/pkg/machinery/compatibility/talos_version.go +++ b/pkg/machinery/compatibility/talos_version.go @@ -17,6 +17,7 @@ import ( "github.com/siderolabs/talos/pkg/machinery/compatibility/talos15" "github.com/siderolabs/talos/pkg/machinery/compatibility/talos16" "github.com/siderolabs/talos/pkg/machinery/compatibility/talos17" + "github.com/siderolabs/talos/pkg/machinery/compatibility/talos18" ) // TalosVersion embeds Talos version. @@ -79,6 +80,9 @@ func (v *TalosVersion) UpgradeableFrom(host *TalosVersion) error { case talos17.MajorMinor: // upgrades to 1.7.x minHostUpgradeVersion, maxHostDowngradeVersion = talos17.MinimumHostUpgradeVersion, talos17.MaximumHostDowngradeVersion deniedHostUpgradeVersions = talos17.DeniedHostUpgradeVersions + case talos18.MajorMinor: // upgrades to 1.8.x + minHostUpgradeVersion, maxHostDowngradeVersion = talos18.MinimumHostUpgradeVersion, talos18.MaximumHostDowngradeVersion + deniedHostUpgradeVersions = talos18.DeniedHostUpgradeVersions default: return fmt.Errorf("upgrades to version %s are not supported", v.version.String()) } diff --git a/pkg/machinery/compatibility/talos_version_test.go b/pkg/machinery/compatibility/talos_version_test.go index 3c3d322cf8..b9b9a0243d 100644 --- a/pkg/machinery/compatibility/talos_version_test.go +++ b/pkg/machinery/compatibility/talos_version_test.go @@ -245,18 +245,59 @@ func TestTalosUpgradeCompatibility17(t *testing.T) { } } -func TestTalosUpgradeCompatibilityUnsupported(t *testing.T) { +func TestTalosUpgradeCompatibility18(t *testing.T) { for _, tt := range []talosVersionTest{ { - host: "1.3.0", - target: "1.8.0-alpha.0", - expectedError: `upgrades to version 1.8.0-alpha.0 are not supported`, + host: "1.6.0", + target: "1.8.0", + }, + { + host: "1.5.0-alpha.0", + target: "1.8.0", + }, + { + host: "1.5.0", + target: "1.8.0-alpha.0", + }, + { + host: "1.7.0", + target: "1.8.1", + }, + { + host: "1.7.0-beta.0", + target: "1.8.0", + }, + { + host: "1.9.5", + target: "1.8.3", }, { host: "1.4.0", + target: "1.8.0", + expectedError: `host version 1.4.0 is too old to upgrade to Talos 1.8.0`, + }, + { + host: "1.10.0-alpha.0", + target: "1.8.0", + expectedError: `host version 1.10.0-alpha.0 is too new to downgrade to Talos 1.8.0`, + }, + } { + runTalosVersionTest(t, tt) + } +} + +func TestTalosUpgradeCompatibilityUnsupported(t *testing.T) { + for _, tt := range []talosVersionTest{ + { + host: "1.3.0", target: "1.9.0-alpha.0", expectedError: `upgrades to version 1.9.0-alpha.0 are not supported`, }, + { + host: "1.4.0", + target: "1.10.0-alpha.0", + expectedError: `upgrades to version 1.10.0-alpha.0 are not supported`, + }, } { runTalosVersionTest(t, tt) }