From b3568a67a8a9ac2adba6308bf12e5c10daee119d Mon Sep 17 00:00:00 2001 From: Stephane Jeandeaux Date: Fri, 19 Apr 2024 21:39:24 +0200 Subject: [PATCH 1/4] helm uninstall The goal is to have the same behaviour with or without dry-run with --ignore-not-found close #12970 Signed-off-by: Stephane Jeandeaux --- pkg/action/uninstall.go | 9 ++++++--- pkg/action/uninstall_test.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 61e10b2c8..6306a93b4 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -66,12 +66,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 { diff --git a/pkg/action/uninstall_test.go b/pkg/action/uninstall_test.go index 8b148522c..8e8af7493 100644 --- a/pkg/action/uninstall_test.go +++ b/pkg/action/uninstall_test.go @@ -34,6 +34,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 @@ -44,7 +55,6 @@ func TestUninstallRelease_ignoreNotFound(t *testing.T) { is.Nil(res) is.NoError(err) } - func TestUninstallRelease_deleteRelease(t *testing.T) { is := assert.New(t) From 65209bed54189bb316c03d92c52bb91c85484998 Mon Sep 17 00:00:00 2001 From: Stephane Jeandeaux Date: Mon, 13 May 2024 20:17:38 +0200 Subject: [PATCH 2/4] Update pkg/action/uninstall.go Co-authored-by: Eddy Moulton Signed-off-by: Stephane Jeandeaux --- pkg/action/uninstall.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 6306a93b4..2a47510d7 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -68,10 +68,10 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) if u.DryRun { r, err := u.cfg.releaseContent(name, 0) switch { - case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound): - fallthrough case err == nil: return &release.UninstallReleaseResponse{Release: r}, nil + case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound): + fallthrough default: return &release.UninstallReleaseResponse{}, err } From 8434935a3dae47a6cdc94388f19e52709d4ea54f Mon Sep 17 00:00:00 2001 From: Stephane Jeandeaux Date: Mon, 13 May 2024 20:40:00 +0200 Subject: [PATCH 3/4] fix fallthrough Signed-off-by: Stephane Jeandeaux --- pkg/action/uninstall.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 2a47510d7..6de570753 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -69,9 +69,9 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) r, err := u.cfg.releaseContent(name, 0) switch { case err == nil: - return &release.UninstallReleaseResponse{Release: r}, nil - case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound): fallthrough + case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound): + return &release.UninstallReleaseResponse{Release: r}, nil default: return &release.UninstallReleaseResponse{}, err } From 44a594fef5693aff44b9ff0f1ea38dacc7fcb880 Mon Sep 17 00:00:00 2001 From: Stephane Jeandeaux Date: Fri, 2 Aug 2024 11:21:23 +0200 Subject: [PATCH 4/4] review Signed-off-by: Stephane Jeandeaux --- pkg/action/uninstall.go | 13 +++++++------ pkg/action/uninstall_test.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 6de570753..163af290e 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -17,6 +17,7 @@ limitations under the License. package action import ( + "errors" "fmt" "log/slog" "strings" @@ -28,6 +29,7 @@ import ( "helm.sh/helm/v4/pkg/kube" releaseutil "helm.sh/helm/v4/pkg/release/util" release "helm.sh/helm/v4/pkg/release/v1" + "helm.sh/helm/v4/pkg/storage/driver" helmtime "helm.sh/helm/v4/pkg/time" ) @@ -67,14 +69,13 @@ func (u *Uninstall) Run(name string) (*release.UninstallReleaseResponse, error) if u.DryRun { r, err := u.cfg.releaseContent(name, 0) - switch { - case err == nil: - fallthrough - case u.IgnoreNotFound && errors.As(err, &driver.ErrReleaseNotFound): - return &release.UninstallReleaseResponse{Release: r}, nil - default: + if err != nil { + if u.IgnoreNotFound && errors.Is(err, driver.ErrReleaseNotFound) { + return nil, nil + } return &release.UninstallReleaseResponse{}, err } + return &release.UninstallReleaseResponse{Release: r}, nil } if err := chartutil.ValidateReleaseName(name); err != nil { diff --git a/pkg/action/uninstall_test.go b/pkg/action/uninstall_test.go index 8e8af7493..44bd66d96 100644 --- a/pkg/action/uninstall_test.go +++ b/pkg/action/uninstall_test.go @@ -41,7 +41,7 @@ func TestUninstallRelease_dryRun_ignoreNotFound(t *testing.T) { is := assert.New(t) res, err := unAction.Run("release-non-exist") - is.NotNil(res) + is.Nil(res) is.NoError(err) }