Skip to content

Commit

Permalink
fix: reinstall previously uninstalled chart with --keep-history
Browse files Browse the repository at this point in the history
Before, if a chart was uninstalled using the `--keep-history` flag, the
next attempt to upgrade/install the chart would result in an error.

This commit fixes that by correctly checking if the last release of the
chart stored in history has been uninstalled and running the install
with the `--replace` flag if that's the case.

Signed-off-by: Alex Petrov <[email protected]>
  • Loading branch information
alex-petrov-vt committed Nov 24, 2022
1 parent 3974136 commit 9e198fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" does not exist. Installing it now.
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
7 changes: 6 additions & 1 deletion cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage/driver"
)

Expand Down Expand Up @@ -96,7 +97,8 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
// If a release does not exist, install it.
histClient := action.NewHistory(cfg)
histClient.Max = 1
if _, err := histClient.Run(args[0]); err == driver.ErrReleaseNotFound {
rel, err := histClient.Run(args[0])
if err == driver.ErrReleaseNotFound || (len(rel) > 0 && rel[len(rel)-1].Info.Status == release.StatusUninstalled) {
// Only print this to stdout for table output
if outfmt == output.Table {
fmt.Fprintf(out, "Release %q does not exist. Installing it now.\n", args[0])
Expand All @@ -118,6 +120,9 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.SubNotes = client.SubNotes
instClient.Description = client.Description
instClient.DependencyUpdate = client.DependencyUpdate
if len(rel) > 0 && rel[len(rel)-1].Info.Status == release.StatusUninstalled {
instClient.Replace = true
}

rel, err := runInstall(args, instClient, valueOpts, out)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/helm/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func TestUpgradeCmd(t *testing.T) {
wantError: true,
rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, release.StatusPendingInstall)},
},
{
name: "install a previously uninstalled release with '--keep-history' using 'upgrade --install'",
cmd: fmt.Sprintf("upgrade funny-bunny -i '%s'", chartPath),
golden: "output/upgrade-uninstalled-with-keep-history.txt",
rels: []*release.Release{relWithStatusMock("funny-bunny", 2, ch, release.StatusUninstalled)},
},
}
runTestCmd(t, tests)
}
Expand Down

0 comments on commit 9e198fa

Please sign in to comment.