Skip to content

Commit

Permalink
Return InvalidUpgradeError
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse committed Sep 8, 2023
1 parent 439132f commit 36fcbdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 8 additions & 6 deletions cli/internal/helm/actionfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ func (a actionFactory) appendNewAction(release Release, configTargetVersion semv
if errors.Is(err, errReleaseNotFound) {
// Don't install a new release if the user's config specifies a different version than the CLI offers.
if !force && isCLIVersionedRelease(release.ReleaseName) && cliSupportsConfigVersion {
return fmt.Errorf(
"unable to install release %s at %s: this CLI only supports microservice version %s for upgrading",
release.ReleaseName, configTargetVersion, newVersion,
return compatibility.NewInvalidUpgradeError(
currentVersion.String(),
configTargetVersion.String(),
fmt.Errorf("this CLI only supports installing microservice version %s", newVersion),
)
}

Expand All @@ -107,9 +108,10 @@ func (a actionFactory) appendNewAction(release Release, configTargetVersion semv
// Target version is newer than current version, so we should perform an upgrade.
// Now make sure the target version is equal to the the CLI version.
if cliSupportsConfigVersion {
return fmt.Errorf(
"unable to upgrade release %s to %s: this CLI only supports microservice version %s for upgrading",
release.ReleaseName, configTargetVersion, newVersion,
return compatibility.NewInvalidUpgradeError(
currentVersion.String(),
configTargetVersion.String(),
fmt.Errorf("this CLI only supports upgrading to microservice version %s", newVersion),
)
}
} else {
Expand Down
6 changes: 2 additions & 4 deletions cli/internal/helm/actionfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ func TestAppendNewAction(t *testing.T) {
},
configTargetVersion: semver.NewFromInt(1, 1, 0, ""),
wantErr: true,
assertErr: func(assert *assert.Assertions, err error) {
var invalidUpgrade *compatibility.InvalidUpgradeError
assert.False(errors.As(err, &invalidUpgrade))
},
assertErr: assertUpgradeErr,
},
"config version matches CLI version on upgrade": {
lister: stubLister{version: semver.NewFromInt(1, 0, 0, "")},
Expand Down Expand Up @@ -220,6 +217,7 @@ func TestAppendNewAction(t *testing.T) {
},
configTargetVersion: semver.NewFromInt(1, 0, 0, ""),
wantErr: true,
assertErr: assertUpgradeErr,
},
"config - CLI version mismatch for new releases can be forced through": {
lister: stubLister{err: errReleaseNotFound},
Expand Down

0 comments on commit 36fcbdf

Please sign in to comment.