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>
  • Loading branch information
alex-petrov-vt committed Nov 26, 2022
1 parent 9e198fa commit f908379
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit f908379

Please sign in to comment.