...

Source file src/edge-infra.dev/pkg/k8s/konfigkonnector/apis/meta/annotations.go

Documentation: edge-infra.dev/pkg/k8s/konfigkonnector/apis/meta

     1  package meta
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  )
     9  
    10  // domain is root domain for all GCP K8s Config Connector annotations/labels/apiVersions
    11  const domain = "cnrm.cloud.google.com"
    12  
    13  // ProjectAnnotation defines where GCP K8s Config Connector will schedule the
    14  // annotated resource
    15  const ProjectAnnotation = domain + "/project-id"
    16  
    17  // FolderAnnotation defines where GCP K8s Config Connector will schedule the
    18  // annotated resource
    19  const FolderAnnotation = domain + "/folder-id"
    20  
    21  // DeletionPolicyAnnotation controls what happens to underlying GCP resources when the
    22  // annotated resource is deleted. See https://cloud.google.com/config-connector/docs/how-to/managing-deleting-resources
    23  const DeletionPolicyAnnotation = domain + "/deletion-policy"
    24  
    25  // DeletionPolicyAbandon means that the GCP resource is not deleted when the annotated resource is deleted
    26  const DeletionPolicyAbandon = "abandon"
    27  
    28  const RemoveDefaultNodePoolAnnotation = domain + "/remove-default-node-pool"
    29  
    30  // Group creates a new Group domain based on the GCP base domain
    31  func Group(subdomain string) string {
    32  	return fmt.Sprintf("%s.%s", subdomain, domain)
    33  }
    34  
    35  // GetProjectAnnotation pulls the project ID from the K8s Cfg Connector
    36  // project ID annotation and returns an error if it is not present.
    37  // This isn't foolproof because the annotation can be inherited from the resource
    38  // namespace. This function should check the namespace for an annotation
    39  // if it isnt found on the provided resource
    40  func GetProjectAnnotation(meta metav1.ObjectMeta) (string, error) {
    41  	if metav1.HasAnnotation(meta, ProjectAnnotation) {
    42  		return meta.Annotations[ProjectAnnotation], nil
    43  	}
    44  	return "", errors.New("no gcp project anno, cant create rest of resources, @aw185176 should implement namespace checking")
    45  }
    46  
    47  // SetProjectAnnotation sets the K8s Cfg Connector project ID annotation to the
    48  // provided value.
    49  func SetProjectAnnotation(meta *metav1.ObjectMeta, id string) {
    50  	metav1.SetMetaDataAnnotation(meta, ProjectAnnotation, id)
    51  }
    52  
    53  // DisableSvcOnDestroyAnnotation tells K8s Config Connector to disable the GCP
    54  // Service when the gcpservice object is deleted: https://cloud.google.com/config-connector/docs/reference/resource-docs/serviceusage/service#custom_resource_definition_properties
    55  const DisableSvcOnDestroyAnnotation = domain + "/disable-on-destroy"
    56  
    57  // DisableDepSvcAnnotation tells K8s Config Connector to disable the dependent
    58  // GCP Services when a gcpservice object is deleted: https://cloud.google.com/config-connector/docs/reference/resource-docs/serviceusage/service#custom_resource_definition_properties
    59  const DisableDepSvcAnnotation = domain + "/disable-dependent-services"
    60  

View as plain text