Add a way to delete the resource and keeping backward compatibility

Signed-off-by: Sébastien Prud'homme <sebastien.prudhomme@gmail.com>
pull/4715/head^2
Sébastien Prud'homme 7 years ago
parent 4faacc6f8c
commit 968b26dcc0

@ -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 if using `helm install --replace` on a release that has already been deleted, but
has kept resources. 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 ## Using "Partials" and Template Includes
Sometimes you want to create some reusable parts in your chart, whether Sometimes you want to create some reusable parts in your chart, whether

@ -34,29 +34,33 @@ const resourcePolicyAnno = "helm.sh/resource-policy"
const keepPolicy = "keep" const keepPolicy = "keep"
func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) { func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) {
remaining := []Manifest{} toDelete := []Manifest{}
keep := []Manifest{} toKeep := []Manifest{}
for _, m := range manifests { for _, m := range manifests {
if m.Head.Metadata == nil || m.Head.Metadata.Annotations == nil || len(m.Head.Metadata.Annotations) == 0 { 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 continue
} }
resourcePolicyType, ok := m.Head.Metadata.Annotations[resourcePolicyAnno] resourcePolicyType, ok := m.Head.Metadata.Annotations[resourcePolicyAnno]
if !ok { if !ok {
remaining = append(remaining, m) toDelete = append(toDelete, m)
continue continue
} }
resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType))
if resourcePolicyType == keepPolicy { 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 { } 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 { func summarizeKeptManifests(manifests []Manifest, kubeClient environment.KubeClient, namespace string) string {

Loading…
Cancel
Save