sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/privatedns/link_spec.go (about)

     1  /*
     2  Copyright 2022 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 privatedns
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns"
    23  	"github.com/pkg/errors"
    24  	"k8s.io/utils/ptr"
    25  	infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
    26  	"sigs.k8s.io/cluster-api-provider-azure/azure"
    27  	"sigs.k8s.io/cluster-api-provider-azure/azure/converters"
    28  )
    29  
    30  // LinkSpec defines the specification for a virtual network link in a private DNS zone.
    31  type LinkSpec struct {
    32  	Name              string
    33  	ZoneName          string
    34  	SubscriptionID    string
    35  	VNetResourceGroup string
    36  	VNetName          string
    37  	ResourceGroup     string
    38  	ClusterName       string
    39  	AdditionalTags    infrav1.Tags
    40  }
    41  
    42  // ResourceName returns the name of the virtual network link.
    43  func (s LinkSpec) ResourceName() string {
    44  	return s.Name
    45  }
    46  
    47  // OwnerResourceName returns the zone name of the virtual network link.
    48  func (s LinkSpec) OwnerResourceName() string {
    49  	return s.ZoneName
    50  }
    51  
    52  // ResourceGroupName returns the name of the resource group of the virtual network link.
    53  func (s LinkSpec) ResourceGroupName() string {
    54  	return s.ResourceGroup
    55  }
    56  
    57  // Parameters returns the parameters for the virtual network link.
    58  func (s LinkSpec) Parameters(ctx context.Context, existing interface{}) (params interface{}, err error) {
    59  	if existing != nil {
    60  		_, ok := existing.(armprivatedns.VirtualNetworkLink)
    61  		if !ok {
    62  			return nil, errors.Errorf("%T is not an armprivatedns.VirtualNetworkLink", existing)
    63  		}
    64  		return nil, nil
    65  	}
    66  
    67  	return armprivatedns.VirtualNetworkLink{
    68  		Properties: &armprivatedns.VirtualNetworkLinkProperties{
    69  			VirtualNetwork: &armprivatedns.SubResource{
    70  				ID: ptr.To(azure.VNetID(s.SubscriptionID, s.VNetResourceGroup, s.VNetName)),
    71  			},
    72  			RegistrationEnabled: ptr.To(false),
    73  		},
    74  		Location: ptr.To(azure.Global),
    75  		Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{
    76  			ClusterName: s.ClusterName,
    77  			Lifecycle:   infrav1.ResourceLifecycleOwned,
    78  			Additional:  s.AdditionalTags,
    79  		})),
    80  	}, nil
    81  }