@@ -18,7 +18,8 @@ package v1beta1
1818
1919import (
2020 "fmt"
21- "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-02-01/network"
21+
22+ "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4"
2223
2324 "k8s.io/utils/ptr"
2425
@@ -96,14 +97,15 @@ func (c *AzureCluster) setVnetDefaults() {
9697}
9798
9899func (c * AzureCluster ) setSubnetDefaults () {
100+ fmt .Println ("These are the current subnets: " )
101+ fmt .Println (c .Spec .NetworkSpec .Subnets )
99102 clusterSubnet , err := c .Spec .NetworkSpec .GetSubnet (SubnetCluster )
100103 clusterSubnetExists := err == nil
101104 if clusterSubnetExists {
102105 clusterSubnet .setClusterSubnetDefaults (c .ObjectMeta .Name )
103106 c .Spec .NetworkSpec .UpdateSubnet (clusterSubnet , SubnetCluster )
104107 }
105108
106- var cpSubnet SubnetSpec
107109 if c .Spec .ControlPlaneEnabled {
108110 /* if there is a cp subnet set defaults
109111 if no cp subnet and cluster subnet create a default cp subnet */
@@ -120,35 +122,23 @@ func (c *AzureCluster) setSubnetDefaults() {
120122
121123 var nodeSubnetFound bool
122124 var nodeSubnetCounter int
123- for i , subnet := range c .Spec .NetworkSpec .Subnets {
124- if subnet . Role == SubnetNode || subnet .Role == SubnetAll {
125+ for i := range c .Spec .NetworkSpec .Subnets {
126+ if c . Spec . NetworkSpec . Subnets [ i ]. Role == SubnetNode || c . Spec . NetworkSpec . Subnets [ i ] .Role == SubnetAll {
125127 nodeSubnetCounter ++
126128 nodeSubnetFound = true
127- if subnet .Name == "" {
128- subnet .Name = withIndex (generateNodeSubnetName (c .ObjectMeta .Name ), nodeSubnetCounter )
129- }
130- subnet .SubnetClassSpec .setDefaults (fmt .Sprintf (DefaultNodeSubnetCIDRPattern , nodeSubnetCounter ))
131-
132- if subnet .SecurityGroup .Name == "" {
133- subnet .SecurityGroup .Name = generateNodeSecurityGroupName (c .ObjectMeta .Name )
134- }
135- cpSubnet .SecurityGroup .SecurityGroupClass .setDefaults ()
129+ c .Spec .NetworkSpec .Subnets [i ].setNodeSubnetDefaults (c .ObjectMeta .Name , nodeSubnetCounter )
136130
137- if subnet .RouteTable .Name == "" {
138- subnet .RouteTable .Name = generateNodeRouteTableName (c .ObjectMeta .Name )
139- }
140- if subnet .IsNatGatewayEnabled () {
141- if subnet .NatGateway .NatGatewayIP .Name == "" {
142- subnet .NatGateway .NatGatewayIP .Name = generateNatGatewayIPName (subnet .NatGateway .Name )
131+ if c .Spec .NetworkSpec .Subnets [i ].IsNatGatewayEnabled () {
132+ if c .Spec .NetworkSpec .Subnets [i ].NatGateway .NatGatewayIP .Name == "" {
133+ c .Spec .NetworkSpec .Subnets [i ].NatGateway .NatGatewayIP .Name = generateNatGatewayIPName (c .Spec .NetworkSpec .Subnets [i ].NatGateway .Name )
143134 }
144135 }
145-
146- c .Spec .NetworkSpec .Subnets [i ] = subnet
147136 }
148137 }
149138
150139 if ! nodeSubnetFound && ! clusterSubnetExists {
151140 nodeSubnet := SubnetSpec {
141+ //Name: generateNodeSubnetName(c.ObjectMeta.Name),
152142 SubnetClassSpec : SubnetClassSpec {
153143 Role : SubnetNode ,
154144 CIDRBlocks : []string {DefaultNodeSubnetCIDR },
@@ -172,8 +162,10 @@ func (c *AzureCluster) setSubnetDefaults() {
172162
173163func (s * SubnetSpec ) setNodeSubnetDefaults (clusterName string , index int ) {
174164 if s .Name == "" {
165+ fmt .Println ("node subnet name is empty: " , s .Name )
175166 s .Name = withIndex (generateNodeSubnetName (clusterName ), index )
176167 }
168+ fmt .Println ("node subnet name: " , s .Name )
177169 s .SubnetClassSpec .setDefaults (fmt .Sprintf (DefaultNodeSubnetCIDRPattern , index ))
178170
179171 if s .SecurityGroup .Name == "" {
@@ -200,8 +192,10 @@ func (s *SubnetSpec) setNodeSubnetDefaults(clusterName string, index int) {
200192
201193func (s * SubnetSpec ) setControlPlaneSubnetDefaults (clusterName string ) {
202194 if s .Name == "" {
195+ fmt .Println ("control plane subnet name is empty: " , s .Name )
203196 s .Name = generateControlPlaneSubnetName (clusterName )
204197 }
198+ fmt .Println ("control plane subnet name: " , s .Name )
205199
206200 s .SubnetClassSpec .setDefaults (DefaultControlPlaneSubnetCIDR )
207201
@@ -455,7 +449,7 @@ func (lb *LoadBalancerClassSpec) setAPIServerLBDefaults() {
455449 lb .SKU = SKUStandard
456450 }
457451 if lb .IPAllocationMethod == "" {
458- lb .IPAllocationMethod = string (network .IPAllocationMethodDynamic )
452+ lb .IPAllocationMethod = string (armnetwork .IPAllocationMethodDynamic )
459453 }
460454 if lb .IdleTimeoutInMinutes == nil {
461455 lb .IdleTimeoutInMinutes = ptr.To [int32 ](DefaultOutboundRuleIdleTimeoutInMinutes )
0 commit comments