Skip to content

Commit

Permalink
refactor: create a helper for checking if a release is uninstalled
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Petrov <alex.petrov.vt@gmail.com>
(cherry picked from commit f908379)
  • Loading branch information
alex-petrov-vt authored and mattfarina committed Apr 10, 2024
1 parent 5a11c76 commit 81c902a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/helm/upgrade.go
Expand Up @@ -121,8 +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
rel, err := histClient.Run(args[0])
if err == driver.ErrReleaseNotFound || (len(rel) > 0 && rel[len(rel)-1].Info.Status == release.StatusUninstalled) {
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 All @@ -148,7 +148,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
instClient.DependencyUpdate = client.DependencyUpdate
instClient.Labels = client.Labels
instClient.EnableDNS = client.EnableDNS
if len(rel) > 0 && rel[len(rel)-1].Info.Status == release.StatusUninstalled {
if isReleaseUninstalled(versions) {
instClient.Replace = true
}

Expand Down Expand Up @@ -290,3 +290,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
}

0 comments on commit 81c902a

Please sign in to comment.