diff --git a/cli/internal/kubecmd/kubecmd.go b/cli/internal/kubecmd/kubecmd.go index 4f9f84eded..0b93119b25 100644 --- a/cli/internal/kubecmd/kubecmd.go +++ b/cli/internal/kubecmd/kubecmd.go @@ -145,8 +145,14 @@ func (k *KubeCmd) UpgradeNodeVersion(ctx context.Context, conf *config.Config, f err = compatibility.NewInvalidUpgradeError(nodeVersion.Spec.KubernetesClusterVersion, string(conf.KubernetesVersion), innerErr) } else { - versionConfig := versions.VersionConfigs[conf.KubernetesVersion] - components, err = k.updateK8s(&nodeVersion, versionConfig.ClusterVersion, versionConfig.KubernetesComponents, force) + versionConfig, ok := versions.VersionConfigs[conf.KubernetesVersion] + if !ok { + err = compatibility.NewInvalidUpgradeError(nodeVersion.Spec.KubernetesClusterVersion, + string(conf.KubernetesVersion), fmt.Errorf("no version config matching K8s %s", conf.KubernetesVersion)) + } else { + components, err = k.prepareUpdateK8s(&nodeVersion, versionConfig.ClusterVersion, + versionConfig.KubernetesComponents, force) + } } switch { @@ -161,7 +167,6 @@ func (k *KubeCmd) UpgradeNodeVersion(ctx context.Context, conf *config.Config, f return fmt.Errorf("updating Kubernetes version: %w", err) } } - if len(upgradeErrs) == 2 { return errors.Join(upgradeErrs...) } @@ -423,7 +428,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 fd8cb61ec0..9d1d37896b 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)