sigs.k8s.io/cluster-api-provider-azure@v1.14.3/api/v1beta1/azuremanagedcontrolplanetemplate_default.go (about) 1 /* 2 Copyright 2023 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 v1beta1 18 19 import ( 20 "strings" 21 22 "k8s.io/utils/ptr" 23 ) 24 25 func (mcp *AzureManagedControlPlaneTemplate) setDefaults() { 26 setDefault[*string](&mcp.Spec.Template.Spec.NetworkPlugin, ptr.To(AzureNetworkPluginName)) 27 setDefault[*string](&mcp.Spec.Template.Spec.LoadBalancerSKU, ptr.To("Standard")) 28 setDefault[*bool](&mcp.Spec.Template.Spec.EnablePreviewFeatures, ptr.To(false)) 29 30 if mcp.Spec.Template.Spec.Version != "" && !strings.HasPrefix(mcp.Spec.Template.Spec.Version, "v") { 31 mcp.Spec.Template.Spec.Version = setDefaultVersion(mcp.Spec.Template.Spec.Version) 32 } 33 34 mcp.setDefaultVirtualNetwork() 35 mcp.setDefaultSubnet() 36 mcp.Spec.Template.Spec.SKU = setDefaultSku(mcp.Spec.Template.Spec.SKU) 37 mcp.Spec.Template.Spec.AutoScalerProfile = setDefaultAutoScalerProfile(mcp.Spec.Template.Spec.AutoScalerProfile) 38 } 39 40 // setDefaultVirtualNetwork sets the default VirtualNetwork for an AzureManagedControlPlaneTemplate. 41 func (mcp *AzureManagedControlPlaneTemplate) setDefaultVirtualNetwork() { 42 if mcp.Spec.Template.Spec.VirtualNetwork.Name == "" { 43 mcp.Spec.Template.Spec.VirtualNetwork.Name = mcp.Name 44 } 45 if mcp.Spec.Template.Spec.VirtualNetwork.CIDRBlock == "" { 46 mcp.Spec.Template.Spec.VirtualNetwork.CIDRBlock = defaultAKSVnetCIDR 47 } 48 } 49 50 // setDefaultSubnet sets the default Subnet for an AzureManagedControlPlaneTemplate. 51 func (mcp *AzureManagedControlPlaneTemplate) setDefaultSubnet() { 52 if mcp.Spec.Template.Spec.VirtualNetwork.Subnet.Name == "" { 53 mcp.Spec.Template.Spec.VirtualNetwork.Subnet.Name = mcp.Name 54 } 55 if mcp.Spec.Template.Spec.VirtualNetwork.Subnet.CIDRBlock == "" { 56 mcp.Spec.Template.Spec.VirtualNetwork.Subnet.CIDRBlock = defaultAKSNodeSubnetCIDR 57 } 58 } 59 60 // setDefault sets the default value for a pointer to a value for any comparable type. 61 func setDefault[T comparable](field *T, value T) { 62 if field == nil { 63 // shouldn't happen with proper use 64 return 65 } 66 var zero T 67 if *field == zero { 68 *field = value 69 } 70 }