github.com/zoumo/helm@v2.5.0+incompatible/pkg/tiller/resource_policy.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tiller 18 19 import ( 20 "strings" 21 ) 22 23 // resourcePolicyAnno is the annotation name for a resource policy 24 const resourcePolicyAnno = "helm.sh/resource-policy" 25 26 // keepPolicy is the resource policy type for keep 27 // 28 // This resource policy type allows resources to skip being deleted 29 // during an uninstallRelease action. 30 const keepPolicy = "keep" 31 32 func filterManifestsToKeep(manifests []manifest) ([]manifest, []manifest) { 33 remaining := []manifest{} 34 keep := []manifest{} 35 36 for _, m := range manifests { 37 38 if m.head.Metadata == nil || m.head.Metadata.Annotations == nil || len(m.head.Metadata.Annotations) == 0 { 39 remaining = append(remaining, m) 40 continue 41 } 42 43 resourcePolicyType, ok := m.head.Metadata.Annotations[resourcePolicyAnno] 44 if !ok { 45 remaining = append(remaining, m) 46 continue 47 } 48 49 resourcePolicyType = strings.ToLower(strings.TrimSpace(resourcePolicyType)) 50 if resourcePolicyType == keepPolicy { 51 keep = append(keep, m) 52 } 53 54 } 55 return keep, remaining 56 } 57 58 func summarizeKeptManifests(manifests []manifest) string { 59 message := "These resources were kept due to the resource policy:\n" 60 for _, m := range manifests { 61 details := "[" + m.head.Kind + "] " + m.head.Metadata.Name + "\n" 62 message = message + details 63 } 64 return message 65 }