From 8fbcfee16ad6e35a407f897def1ccda857cf0f85 Mon Sep 17 00:00:00 2001 From: zze <632404164@qq.com> Date: Tue, 12 Apr 2022 16:19:25 +0800 Subject: [PATCH 1/4] feat: Add --only--release option to uninstall --- cmd/helm/uninstall.go | 1 + pkg/action/resource_policy.go | 8 +++++++- pkg/action/uninstall.go | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/helm/uninstall.go b/cmd/helm/uninstall.go index 67f778f15..fc992489a 100644 --- a/cmd/helm/uninstall.go +++ b/cmd/helm/uninstall.go @@ -68,6 +68,7 @@ func newUninstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } f := cmd.Flags() + f.BoolVar(&client.OnlyRelease, "only-release", false, "keep all k8s resources when uninstall") 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.KeepHistory, "keep-history", false, "remove all associated resources and mark the release as deleted, but retain the release history") diff --git a/pkg/action/resource_policy.go b/pkg/action/resource_policy.go index 63e83f3d9..5c8cab6e8 100644 --- a/pkg/action/resource_policy.go +++ b/pkg/action/resource_policy.go @@ -23,8 +23,14 @@ import ( "helm.sh/helm/v3/pkg/releaseutil" ) -func filterManifestsToKeep(manifests []releaseutil.Manifest) (keep, remaining []releaseutil.Manifest) { +func filterManifestsToKeep(manifests []releaseutil.Manifest, onlyRelease bool) (keep, remaining []releaseutil.Manifest) { for _, m := range manifests { + if onlyRelease { + if m.Head.Metadata != nil { + keep = append(keep, m) + } + continue + } if m.Head.Metadata == nil || m.Head.Metadata.Annotations == nil || len(m.Head.Metadata.Annotations) == 0 { remaining = append(remaining, m) continue diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index 65993df4c..4e7c7e06d 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -36,6 +36,7 @@ type Uninstall struct { cfg *Configuration DisableHooks bool + OnlyRelease bool DryRun bool KeepHistory bool Wait bool @@ -200,7 +201,7 @@ func (u *Uninstall) deleteRelease(rel *release.Release) (kube.ResourceList, stri return nil, rel.Manifest, []error{errors.Wrap(err, "corrupted release record. You must manually delete the resources")} } - filesToKeep, filesToDelete := filterManifestsToKeep(files) + filesToKeep, filesToDelete := filterManifestsToKeep(files, u.OnlyRelease) var kept string for _, f := range filesToKeep { kept += "[" + f.Head.Kind + "] " + f.Head.Metadata.Name + "\n" From fe21b34ae3eda52a317cfaf922051ac74036a6a6 Mon Sep 17 00:00:00 2001 From: zze <632404164@qq.com> Date: Tue, 12 Apr 2022 17:35:47 +0800 Subject: [PATCH 2/4] pref: build for linux --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 0a7b326a8..d54e3758d 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,13 @@ build: $(BINDIR)/$(BINNAME) $(BINDIR)/$(BINNAME): $(SRC) GO111MODULE=on CGO_ENABLED=0 go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm + +.PHONY: build-linux-amd64 +build-linux-amd64: $(BINDIR)/$(BINNAME) + +$(BINDIR)/$(BINNAME): $(SRC) + GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm + # ------------------------------------------------------------------------------ # install From 26bec2585ecc2fde22405dd92ae70d8baffb9df8 Mon Sep 17 00:00:00 2001 From: zze <632404164@qq.com> Date: Tue, 12 Apr 2022 17:41:34 +0800 Subject: [PATCH 3/4] fix --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d54e3758d..b54db9efe 100644 --- a/Makefile +++ b/Makefile @@ -81,9 +81,9 @@ $(BINDIR)/$(BINNAME): $(SRC) .PHONY: build-linux-amd64 -build-linux-amd64: $(BINDIR)/$(BINNAME) +build-linux-amd64: $(BINDIR)/$(BINNAME)-linux-amd64 -$(BINDIR)/$(BINNAME): $(SRC) +$(BINDIR)/$(BINNAME)-linux-amd64: $(SRC) GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm # ------------------------------------------------------------------------------ From 1d85bd20e87bbdcc1a4b09d77183d8159738cda4 Mon Sep 17 00:00:00 2001 From: zze326 <49554487+zze326@users.noreply.github.com> Date: Tue, 19 Apr 2022 18:08:26 +0800 Subject: [PATCH 4/4] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8161e1fdc..bee3fa1ea 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module helm.sh/helm/v3 +module github.com/zze326/helm go 1.17