github.com/koderover/helm@v2.17.0+incompatible/pkg/tiller/resource_policy.go (about) 1 /* 2 Copyright The Helm Authors. 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 "bytes" 21 "strings" 22 23 "k8s.io/helm/pkg/kube" 24 "k8s.io/helm/pkg/tiller/environment" 25 ) 26 27 func filterManifestsToKeep(manifests []Manifest) ([]Manifest, []Manifest) { 28 remaining := []Manifest{} 29 keep := []Manifest{} 30 31 for _, m := range manifests { 32 if m.Head.Metadata == nil || m.Head.Metadata.Annotations == nil || len(m.Head.Metadata.Annotations) == 0 { 33 remaining = append(remaining, m) 34 continue 35 } 36 37 if kube.ResourcePolicyIsKeep(m.Head.Metadata.Annotations) { 38 keep = append(keep, m) 39 } else { 40 remaining = append(remaining, m) 41 } 42 } 43 return keep, remaining 44 } 45 46 func summarizeKeptManifests(manifests []Manifest, kubeClient environment.KubeClient, namespace string) string { 47 var message string 48 for _, m := range manifests { 49 // check if m is in fact present from k8s client's POV. 50 output, err := kubeClient.Get(namespace, bytes.NewBufferString(m.Content)) 51 if err != nil || strings.Contains(output, kube.MissingGetHeader) { 52 continue 53 } 54 55 details := "[" + m.Head.Kind + "] " + m.Head.Metadata.Name + "\n" 56 if message == "" { 57 message = "These resources were kept due to the resource policy:\n" 58 } 59 message = message + details 60 } 61 return message 62 }