Skip to content

Commit

Permalink
Merge pull request helm#10564 from suzaku/ignore-not-found
Browse files Browse the repository at this point in the history
Closes helm#3352, add support for --ignore-not-found just like kubectl delete
  • Loading branch information
joejulian authored Aug 11, 2023
2 parents a680f72 + 5b08985 commit 1a465d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/helm/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func newUninstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVar(&client.DryRun, "dry-run", false, "simulate a uninstall")
f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during uninstallation")
f.BoolVar(&client.IgnoreNotFound, "ignore-not-found", false, `Treat "release not found" as a successful uninstall`)
f.BoolVar(&client.KeepHistory, "keep-history", false, "remove all associated resources and mark the release as deleted, but retain the release history")
f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all the resources are deleted before returning. It will wait for as long as --timeout")
f.StringVar(&client.DeletionPropagation, "cascade", "background", "Must be \"background\", \"orphan\", or \"foreground\". Selects the deletion cascading strategy for the dependents. Defaults to background.")
Expand Down
5 changes: 5 additions & 0 deletions pkg/action/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/pkg/errors"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"helm.sh/helm/v3/pkg/chartutil"
Expand All @@ -38,6 +39,7 @@ type Uninstall struct {

DisableHooks bool
DryRun bool
IgnoreNotFound bool
KeepHistory bool
Wait bool
DeletionPropagation string
Expand Down Expand Up @@ -73,6 +75,9 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)

rels, err := u.cfg.Releases.History(name)
if err != nil {
if u.IgnoreNotFound {
return nil, nil
}
return nil, errors.Wrapf(err, "uninstall: Release not loaded: %s", name)
}
if len(rels) < 1 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/action/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ func uninstallAction(t *testing.T) *Uninstall {
return unAction
}

func TestUninstallRelease_ignoreNotFound(t *testing.T) {
unAction := uninstallAction(t)
unAction.DryRun = false
unAction.IgnoreNotFound = true

is := assert.New(t)
res, err := unAction.Run("release-non-exist")
is.Nil(res)
is.NoError(err)
}

func TestUninstallRelease_deleteRelease(t *testing.T) {
is := assert.New(t)

Expand Down

0 comments on commit 1a465d6

Please sign in to comment.