sigs.k8s.io/cluster-api-provider-azure@v1.14.3/azure/services/routetables/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 routetables
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4"
    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/converters"
    27  )
    28  
    29  // RouteTableSpec defines the specification for a route table.
    30  type RouteTableSpec struct {
    31  	Name           string
    32  	ResourceGroup  string
    33  	Location       string
    34  	ClusterName    string
    35  	AdditionalTags infrav1.Tags
    36  }
    37  
    38  // ResourceName returns the name of the route table.
    39  func (s *RouteTableSpec) ResourceName() string {
    40  	return s.Name
    41  }
    42  
    43  // ResourceGroupName returns the name of the resource group.
    44  func (s *RouteTableSpec) ResourceGroupName() string {
    45  	return s.ResourceGroup
    46  }
    47  
    48  // OwnerResourceName is a no-op for route tables.
    49  func (s *RouteTableSpec) OwnerResourceName() string {
    50  	return ""
    51  }
    52  
    53  // Parameters returns the parameters for the route table.
    54  func (s *RouteTableSpec) Parameters(ctx context.Context, existing interface{}) (params interface{}, err error) {
    55  	if existing != nil {
    56  		if _, ok := existing.(armnetwork.RouteTable); !ok {
    57  			return nil, errors.Errorf("%T is not an armnetwork.RouteTable", existing)
    58  		}
    59  		// route table already exists
    60  		// currently don't support specifying your own routes via spec.
    61  		return nil, nil
    62  	}
    63  	return armnetwork.RouteTable{
    64  		Location:   ptr.To(s.Location),
    65  		Properties: &armnetwork.RouteTablePropertiesFormat{},
    66  		Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{
    67  			ClusterName: s.ClusterName,
    68  			Lifecycle:   infrav1.ResourceLifecycleOwned,
    69  			Name:        ptr.To(s.Name),
    70  			Additional:  s.AdditionalTags,
    71  		})),
    72  	}, nil
    73  }