package meta import ( "errors" "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // domain is root domain for all GCP K8s Config Connector annotations/labels/apiVersions const domain = "cnrm.cloud.google.com" // ProjectAnnotation defines where GCP K8s Config Connector will schedule the // annotated resource const ProjectAnnotation = domain + "/project-id" // FolderAnnotation defines where GCP K8s Config Connector will schedule the // annotated resource const FolderAnnotation = domain + "/folder-id" // DeletionPolicyAnnotation controls what happens to underlying GCP resources when the // annotated resource is deleted. See https://cloud.google.com/config-connector/docs/how-to/managing-deleting-resources const DeletionPolicyAnnotation = domain + "/deletion-policy" // DeletionPolicyAbandon means that the GCP resource is not deleted when the annotated resource is deleted const DeletionPolicyAbandon = "abandon" const RemoveDefaultNodePoolAnnotation = domain + "/remove-default-node-pool" // Group creates a new Group domain based on the GCP base domain func Group(subdomain string) string { return fmt.Sprintf("%s.%s", subdomain, domain) } // GetProjectAnnotation pulls the project ID from the K8s Cfg Connector // project ID annotation and returns an error if it is not present. // This isn't foolproof because the annotation can be inherited from the resource // namespace. This function should check the namespace for an annotation // if it isnt found on the provided resource func GetProjectAnnotation(meta metav1.ObjectMeta) (string, error) { if metav1.HasAnnotation(meta, ProjectAnnotation) { return meta.Annotations[ProjectAnnotation], nil } return "", errors.New("no gcp project anno, cant create rest of resources, @aw185176 should implement namespace checking") } // SetProjectAnnotation sets the K8s Cfg Connector project ID annotation to the // provided value. func SetProjectAnnotation(meta *metav1.ObjectMeta, id string) { metav1.SetMetaDataAnnotation(meta, ProjectAnnotation, id) } // DisableSvcOnDestroyAnnotation tells K8s Config Connector to disable the GCP // Service when the gcpservice object is deleted: https://cloud.google.com/config-connector/docs/reference/resource-docs/serviceusage/service#custom_resource_definition_properties const DisableSvcOnDestroyAnnotation = domain + "/disable-on-destroy" // DisableDepSvcAnnotation tells K8s Config Connector to disable the dependent // GCP Services when a gcpservice object is deleted: https://cloud.google.com/config-connector/docs/reference/resource-docs/serviceusage/service#custom_resource_definition_properties const DisableDepSvcAnnotation = domain + "/disable-dependent-services"