From f908379f1f8e3d764b0a52dcba2d234490fc0ffc Mon Sep 17 00:00:00 2001 From: Alex Petrov Date: Fri, 25 Nov 2022 21:05:12 -0500 Subject: [PATCH] refactor: create a helper for checking if a release is uninstalled Signed-off-by: Alex Petrov --- cmd/helm/upgrade.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 5d3c1d020..42b59f60a 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -97,8 +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 - 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]) @@ -120,7 +120,7 @@ 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 { + if isReleaseUninstalled(versions) { instClient.Replace = true } @@ -254,3 +254,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 +}