diff --git a/Makefile b/Makefile index d61ac1507..53ddb4c5f 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,13 @@ build: $(BINDIR)/$(BINNAME) $(BINDIR)/$(BINNAME): $(SRC) GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o '$(BINDIR)'/$(BINNAME) ./cmd/helm + +.PHONY: build-linux-amd64 +build-linux-amd64: $(BINDIR)/$(BINNAME)-linux-amd64 + +$(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 + # ------------------------------------------------------------------------------ # install 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/go.mod b/go.mod index 43787d297..412a48a1b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module helm.sh/helm/v3 +module github.com/zze326/helm go 1.19 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 9dcbf19b0..f2d25c3a4 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 @@ -204,7 +205,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"