From fc35de70d9fc8aa85b8943e1c5979f44eb7f0e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Prud=27homme?= Date: Sat, 13 Oct 2018 19:36:13 +0200 Subject: [PATCH] Add a way to delete the resource and keeping backward compatibility --- docs/charts_tips_and_tricks.md | 3 +++ pkg/tiller/resource_policy.go | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/charts_tips_and_tricks.md b/docs/charts_tips_and_tricks.md index a83b44457..a23ff694e 100644 --- a/docs/charts_tips_and_tricks.md +++ b/docs/charts_tips_and_tricks.md @@ -219,6 +219,9 @@ orphaned. Helm will no longer manage it in any way. This can lead to problems if using `helm install --replace` on a release that has already been deleted, but has kept resources. +For backward compatibility, an `"helm.sh/resource-policy"` annotation with an empty +value also means to keep the resource. Any other value means to delete the resource. + ## Using "Partials" and Template Includes Sometimes you want to create some reusable parts in your chart, whether diff --git a/pkg/tiller/resource_policy.go b/pkg/tiller/resource_policy.go index fadae7d57..d2f38d605 100644 --- a/pkg/tiller/resource_policy.go +++ b/pkg/tiller/resource_policy.go @@ -34,29 +34,33 @@ const resourcePolicyAnno = "helm.sh/resource-policy" const keepPolicy = "keep" func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) { - remaining := []Manifest{} - keep := []Manifest{} + toDelete := []Manifest{} + toKeep := []Manifest{} for _, m := range manifests { if m.Head.Metadata == nil || m.Head.Metadata.Annotations == nil || len(m.Head.Metadata.Annotations) == 0 { - remaining = append(remaining, m) + toDelete = append(toDelete, m) continue } resourcePolicyType, ok := m.Head.Metadata.Annotations[resourcePolicyAnno] if !ok { - remaining = append(remaining, m) + toDelete = append(toDelete, m) continue } resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) if resourcePolicyType == keepPolicy { - keep = append(keep, m) + toKeep = append(toKeep, m) + } else if resourcePolicyType == "" { + // Empty annotation means keep in Helm 2 + toKeep = append(toKeep, m) } else { - remaining = append(remaining, m) + // Any other annotation means delete in Helm 2 + toDelete = append(toDelete, m) } } - return keep, remaining + return toKeep, toDelete } func summarizeKeptManifests(manifests []Manifest, kubeClient environment.KubeClient, namespace string) string {