github.com/latiif/helm@v2.15.0+incompatible/pkg/kube/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 kube
    18  
    19  const (
    20  	// ResourcePolicyAnno is the annotation name for a resource policy
    21  	ResourcePolicyAnno = "helm.sh/resource-policy"
    22  
    23  	// deletePolicy is the resource policy type for delete
    24  	//
    25  	// This resource policy type allows explicitly opting in to the default
    26  	//   resource deletion behavior, for example when overriding a chart's
    27  	//   default annotations. Any other value allows resources to skip being
    28  	//   deleted during an uninstallRelease action.
    29  	deletePolicy = "delete"
    30  )
    31  
    32  // ResourcePolicyIsKeep accepts a map of Kubernetes resource annotations and
    33  //   returns true if the resource should be kept, otherwise false if it is safe
    34  //   for Helm to delete.
    35  func ResourcePolicyIsKeep(annotations map[string]string) bool {
    36  	if annotations != nil {
    37  		resourcePolicyType, ok := annotations[ResourcePolicyAnno]
    38  		if ok && resourcePolicyType != deletePolicy {
    39  			return true
    40  		}
    41  	}
    42  	return false
    43  }