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

     1  /*
     2  Copyright 2021 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 natgateways
    18  
    19  import (
    20  	"context"
    21  
    22  	asonetworkv1 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701"
    23  	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
    24  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    25  	"k8s.io/utils/ptr"
    26  	infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
    27  	"sigs.k8s.io/cluster-api-provider-azure/azure"
    28  )
    29  
    30  // NatGatewaySpec defines the specification for a NAT gateway.
    31  type NatGatewaySpec struct {
    32  	Name           string
    33  	ResourceGroup  string
    34  	SubscriptionID string
    35  	Location       string
    36  	NatGatewayIP   infrav1.PublicIPSpec
    37  	ClusterName    string
    38  	AdditionalTags infrav1.Tags
    39  	IsVnetManaged  bool
    40  }
    41  
    42  // ResourceRef implements azure.ASOResourceSpecGetter.
    43  func (s *NatGatewaySpec) ResourceRef() *asonetworkv1.NatGateway {
    44  	return &asonetworkv1.NatGateway{
    45  		ObjectMeta: metav1.ObjectMeta{
    46  			Name: s.Name,
    47  		},
    48  	}
    49  }
    50  
    51  // Parameters implements azure.ASOResourceSpecGetter.
    52  func (s *NatGatewaySpec) Parameters(ctx context.Context, existingNatGateway *asonetworkv1.NatGateway) (params *asonetworkv1.NatGateway, err error) {
    53  	natGateway := &asonetworkv1.NatGateway{}
    54  	natGateway.Spec = asonetworkv1.NatGateway_Spec{}
    55  
    56  	if existingNatGateway != nil {
    57  		natGateway = existingNatGateway
    58  	}
    59  
    60  	natGateway.Spec.AzureName = s.Name
    61  	natGateway.Spec.Owner = &genruntime.KnownResourceReference{
    62  		Name: s.ResourceGroup,
    63  	}
    64  	natGateway.Spec.Location = ptr.To(s.Location)
    65  	natGateway.Spec.Sku = &asonetworkv1.NatGatewaySku{
    66  		Name: ptr.To(asonetworkv1.NatGatewaySku_Name_Standard),
    67  	}
    68  	natGateway.Spec.PublicIpAddresses = []asonetworkv1.ApplicationGatewaySubResource{
    69  		{
    70  			Reference: &genruntime.ResourceReference{
    71  				ARMID: azure.PublicIPID(s.SubscriptionID, s.ResourceGroup, s.NatGatewayIP.Name),
    72  			},
    73  		},
    74  	}
    75  	natGateway.Spec.Tags = infrav1.Build(infrav1.BuildParams{
    76  		ClusterName: s.ClusterName,
    77  		Lifecycle:   infrav1.ResourceLifecycleOwned,
    78  		Name:        ptr.To(s.Name),
    79  		Additional:  s.AdditionalTags,
    80  	})
    81  
    82  	return natGateway, nil
    83  }
    84  
    85  // WasManaged implements azure.ASOResourceSpecGetter.
    86  func (s *NatGatewaySpec) WasManaged(resource *asonetworkv1.NatGateway) bool {
    87  	return s.IsVnetManaged
    88  }