Skip to content

Commit

Permalink
fixup! leo feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Sep 8, 2023
1 parent 02d8442 commit 7d3ce1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions cli/internal/kubecmd/kubecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/internal/kubecmd/kubecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down

0 comments on commit 7d3ce1f

Please sign in to comment.