...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/label/label.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/label

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package label
    16  
    17  import (
    18  	"strings"
    19  )
    20  
    21  func NewGcpFromK8sLabels(labels map[string]string) map[string]string {
    22  	res := RemoveLabelsWithKRMPrefix(labels)
    23  	res[CnrmManagedKey] = "true"
    24  	return res
    25  }
    26  
    27  func RemoveLabelsWithKRMPrefix(labels map[string]string) map[string]string {
    28  	res := make(map[string]string)
    29  	for k, v := range labels {
    30  		if len(strings.Split(k, "/")) == 2 {
    31  			// Do not include any KRM-style labels (labels that include a prefix
    32  			// denoted with a '/').
    33  			// TODO(b/137755194): Determine long-term solution.
    34  			continue
    35  		}
    36  		res[k] = v
    37  	}
    38  	return res
    39  }
    40  
    41  func NewGCPLabelsFromK8SLabels(labelMaps ...map[string]string) map[string]interface{} {
    42  	res := make(map[string]interface{})
    43  	for _, labels := range labelMaps {
    44  		if labels != nil {
    45  			for k, v := range labels {
    46  				if len(strings.Split(k, "/")) == 2 {
    47  					// Do not include any KRM-style labels (labels that include a prefix
    48  					// denoted with a '/').
    49  					// TODO(b/137755194): Determine long-term solution.
    50  					continue
    51  				}
    52  				res[k] = v
    53  			}
    54  		}
    55  	}
    56  	return res
    57  }
    58  
    59  func GetDefaultLabels() map[string]string {
    60  	return map[string]string{
    61  		CnrmManagedKey: "true",
    62  	}
    63  }
    64  

View as plain text