feat: Add --only--release option to uninstall

pull/10853/head
zze 4 years ago
parent cba3b1eed4
commit 8fbcfee16a

@ -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")

@ -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

@ -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"

Loading…
Cancel
Save