Skip to content

Commit

Permalink
Fix helm#3352, add support for --ignore-not-found just like kubectl d…
Browse files Browse the repository at this point in the history
…elete

Signed-off-by: suzaku <satorulogic@gmail.com>
  • Loading branch information
suzaku committed Jan 17, 2022
1 parent c137bfb commit 6e3d1ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/helm/uninstall.go
Expand Up @@ -70,6 +70,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.DurationVar(&client.Timeout, "timeout", 300*time.Second, "time to wait for any individual Kubernetes operation (like Jobs for hooks)")
Expand Down
16 changes: 10 additions & 6 deletions pkg/action/uninstall.go
Expand Up @@ -35,12 +35,13 @@ import (
type Uninstall struct {
cfg *Configuration

DisableHooks bool
DryRun bool
KeepHistory bool
Wait bool
Timeout time.Duration
Description string
DisableHooks bool
DryRun bool
IgnoreNotFound bool
KeepHistory bool
Wait bool
Timeout time.Duration
Description string
}

// NewUninstall creates a new Uninstall object with the given configuration.
Expand Down Expand Up @@ -71,6 +72,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
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 6e3d1ca

Please sign in to comment.