Skip to content

Commit

Permalink
Merge pull request #11569 from alex-petrov-vt/iss-11553
Browse files Browse the repository at this point in the history
fix: reinstall previously uninstalled chart with --keep-history
  • Loading branch information
mattfarina committed Apr 10, 2024
2 parents a753ee7 + 5616713 commit 14d0c13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
@@ -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
12 changes: 11 additions & 1 deletion cmd/helm/upgrade.go
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 @@ -120,7 +121,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 {
versions, err := histClient.Run(args[0])
if err == driver.ErrReleaseNotFound || isReleaseUninstalled(versions) {
// 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 Down Expand Up @@ -148,6 +150,10 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.EnableDNS = client.EnableDNS
instClient.HideSecret = client.HideSecret

if isReleaseUninstalled(versions) {
instClient.Replace = true
}

rel, err := runInstall(args, instClient, valueOpts, out)
if err != nil {
return err
Expand Down Expand Up @@ -287,3 +293,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {

return cmd
}

func isReleaseUninstalled(versions []*release.Release) bool {
return len(versions) > 0 && versions[len(versions)-1].Info.Status == release.StatusUninstalled
}
6 changes: 6 additions & 0 deletions cmd/helm/upgrade_test.go
Expand Up @@ -175,6 +175,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 14d0c13

Please sign in to comment.