From 9462b7020091e65257717beb13f860dde57826c0 Mon Sep 17 00:00:00 2001 From: Adrian Stobbe Date: Fri, 8 Sep 2023 08:36:06 +0200 Subject: [PATCH] fixup! leo feedback --- cli/internal/kubecmd/kubecmd.go | 14 +++++++++----- cli/internal/kubecmd/kubecmd_test.go | 2 +- internal/versions/versions.go | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cli/internal/kubecmd/kubecmd.go b/cli/internal/kubecmd/kubecmd.go index b5fd554ddf..a0d1c98001 100644 --- a/cli/internal/kubecmd/kubecmd.go +++ b/cli/internal/kubecmd/kubecmd.go @@ -136,9 +136,14 @@ func (k *KubeCmd) UpgradeNodeVersion(ctx context.Context, conf *config.Config, f // Therefore, this code has to skip k8s updates if a user configures an outdated (i.e. invalid) k8s version. var components *corev1.ConfigMap currentK8sVersion := conf.KubernetesVersion - versionConfig := versions.VersionConfigs[currentK8sVersion] - components, err = k.updateK8s(&nodeVersion, versionConfig.ClusterVersion, versionConfig.KubernetesComponents, force) - + versionConfig, ok := versions.VersionConfigs[currentK8sVersion] + if !ok { + err = compatibility.NewInvalidUpgradeError(nodeVersion.Spec.KubernetesClusterVersion, + string(currentK8sVersion), fmt.Errorf("no version config matching K8s %s", currentK8sVersion)) + } else { + components, err = k.prepareUpdateK8s(&nodeVersion, versionConfig.ClusterVersion, + versionConfig.KubernetesComponents, force) + } switch { case err == nil: err := k.applyComponentsCM(ctx, components) @@ -150,7 +155,6 @@ func (k *KubeCmd) UpgradeNodeVersion(ctx context.Context, conf *config.Config, f default: return fmt.Errorf("updating Kubernetes version: %w", err) } - if len(upgradeErrs) == 2 { return errors.Join(upgradeErrs...) } @@ -412,7 +416,7 @@ func (k *KubeCmd) isValidImageUpgrade(nodeVersion updatev1alpha1.NodeVersion, ne return nil } -func (k *KubeCmd) updateK8s(nodeVersion *updatev1alpha1.NodeVersion, newClusterVersion string, components components.Components, force bool) (*corev1.ConfigMap, error) { +func (k *KubeCmd) prepareUpdateK8s(nodeVersion *updatev1alpha1.NodeVersion, newClusterVersion string, components components.Components, force bool) (*corev1.ConfigMap, error) { configMap, err := internalk8s.ConstructK8sComponentsCM(components, newClusterVersion) if err != nil { return nil, fmt.Errorf("constructing k8s-components ConfigMap: %w", err) diff --git a/cli/internal/kubecmd/kubecmd_test.go b/cli/internal/kubecmd/kubecmd_test.go index 16bbaa19dc..a2d73bbcdd 100644 --- a/cli/internal/kubecmd/kubecmd_test.go +++ b/cli/internal/kubecmd/kubecmd_test.go @@ -444,7 +444,7 @@ func TestUpdateK8s(t *testing.T) { }, } - _, err := upgrader.updateK8s(&nodeVersion, tc.newClusterVersion, components.Components{}, false) + _, err := upgrader.prepareUpdateK8s(&nodeVersion, tc.newClusterVersion, components.Components{}, false) if tc.wantErr { assert.Error(err) diff --git a/internal/versions/versions.go b/internal/versions/versions.go index d6ce41d0d1..c2a75bd3ae 100644 --- a/internal/versions/versions.go +++ b/internal/versions/versions.go @@ -85,7 +85,7 @@ func ResolveK8sPatchVersion(k8sVersion string) (string, error) { if hasPatchVersion(k8sVersion) { return k8sVersion, nil } - extendedVersion := K8sVersionFromMajorMinor(k8sVersion) + extendedVersion := k8sVersionFromMajorMinor(k8sVersion) if extendedVersion == "" { return "", fmt.Errorf("Kubernetes version %s is not valid. Supported versions: %s", strings.TrimPrefix(k8sVersion, "v"), supportedVersions()) @@ -94,10 +94,10 @@ func ResolveK8sPatchVersion(k8sVersion string) (string, error) { return extendedVersion, nil } -// K8sVersionFromMajorMinor takes a semver in format MAJOR.MINOR +// k8sVersionFromMajorMinor takes a semver in format MAJOR.MINOR // and returns the version in format MAJOR.MINOR.PATCH with the // supported patch version as PATCH. -func K8sVersionFromMajorMinor(version string) string { +func k8sVersionFromMajorMinor(version string) string { switch version { case semver.MajorMinor(string(V1_26)): return string(V1_26)