Skip to content

Commit

Permalink
helm uninstall
Browse files Browse the repository at this point in the history
The goal is to have the same behaviour with or without dry-run with --ignore-not-found

Signed-off-by: Stephane Jeandeaux <stephane.jeandeaux@gmail.com>
  • Loading branch information
sjeandeaux committed Apr 19, 2024
1 parent 14d0c13 commit 688a605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/action/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"helm.sh/helm/v3/pkg/kube"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/releaseutil"
"helm.sh/helm/v3/pkg/storage/driver"
helmtime "helm.sh/helm/v3/pkg/time"
)

Expand Down Expand Up @@ -61,12 +62,15 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error)
}

if u.DryRun {
// In the dry run case, just see if the release exists
r, err := u.cfg.releaseContent(name, 0)
if err != nil {
switch {
case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound):
fallthrough
case err == nil:
return &release.UninstallReleaseResponse{Release: r}, nil
default:
return &release.UninstallReleaseResponse{}, err
}
return &release.UninstallReleaseResponse{Release: r}, nil
}

if err := chartutil.ValidateReleaseName(name); err != nil {
Expand Down
12 changes: 11 additions & 1 deletion 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_dryRun_ignoreNotFound(t *testing.T) {
unAction := uninstallAction(t)
unAction.DryRun = true
unAction.IgnoreNotFound = true

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

func TestUninstallRelease_ignoreNotFound(t *testing.T) {
unAction := uninstallAction(t)
unAction.DryRun = false
Expand All @@ -42,7 +53,6 @@ func TestUninstallRelease_ignoreNotFound(t *testing.T) {
is.Nil(res)
is.NoError(err)
}

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

Expand Down

0 comments on commit 688a605

Please sign in to comment.