sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/converters/tags.go (about)

     1  /*
     2  Copyright 2019 The Kubernetes 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 converters
    18  
    19  import (
    20  	"k8s.io/utils/ptr"
    21  	infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
    22  	"sigs.k8s.io/cluster-api-provider-azure/azure"
    23  )
    24  
    25  // MapToTags converts a map[string]*string into a infrav1.Tags.
    26  func MapToTags(src map[string]*string) infrav1.Tags {
    27  	if src == nil {
    28  		return nil
    29  	}
    30  
    31  	tags := make(infrav1.Tags, len(src))
    32  
    33  	for k, v := range src {
    34  		tags[k] = ptr.Deref(v, "")
    35  	}
    36  
    37  	return tags
    38  }
    39  
    40  // TagsToMap converts infrav1.Tags into a map[string]*string.
    41  func TagsToMap(src infrav1.Tags) map[string]*string {
    42  	return azure.StringMapPtr(src)
    43  }