Skip to content

Commit 3f82514

Browse files
committed
Fix for Subnets & package changes
1 parent aa40534 commit 3f82514

File tree

5 files changed

+42
-49
lines changed

5 files changed

+42
-49
lines changed

api/v1beta1/azurecluster_default.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ package v1beta1
1818

1919
import (
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

9899
func (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

173163
func (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

201193
func (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)

api/v1beta1/azuremachine_default.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,23 @@ func (m *AzureMachine) SetDefaults(client client.Client) error {
223223
}
224224

225225
// Fetch the Cluster.
226-
clusterName, ok := m.Labels[clusterv1.ClusterNameLabel]
227-
if !ok {
228-
errs = append(errs, errors.Errorf("failed to fetch ClusterName for AzureMachine %s/%s", m.Namespace, m.Name))
229-
}
230-
231-
ownerAzureClusterName, ownerAzureClusterNamespace, err := GetOwnerAzureClusterNameAndNamespace(client, clusterName, m.Namespace, 5)
232-
if err != nil {
233-
errs = append(errs, errors.Wrapf(err, "failed to fetch owner cluster for AzureMachine %s/%s", m.Namespace, m.Name))
234-
}
235-
236-
subscriptionID, err := GetSubscriptionID(client, ownerAzureClusterName, ownerAzureClusterNamespace, 5)
237-
if err != nil {
238-
errs = append(errs, errors.Wrapf(err, "failed to fetch subscription ID for AzureMachine %s/%s", m.Namespace, m.Name))
239-
}
226+
//clusterName, ok := m.Labels[clusterv1.ClusterNameLabel]
227+
//if !ok {
228+
// errs = append(errs, errors.Errorf("failed to fetch ClusterName for AzureMachine %s/%s", m.Namespace, m.Name))
229+
//}
230+
231+
//ownerAzureClusterName, ownerAzureClusterNamespace, err := GetOwnerAzureClusterNameAndNamespace(client, clusterName, m.Namespace, 5)
232+
//if err != nil {
233+
// errs = append(errs, errors.Wrapf(err, "failed to fetch owner cluster for AzureMachine %s/%s", m.Namespace, m.Name))
234+
//}
235+
//
236+
//subscriptionID, err := GetSubscriptionID(client, ownerAzureClusterName, ownerAzureClusterNamespace, 5)
237+
//if err != nil {
238+
// errs = append(errs, errors.Wrapf(err, "failed to fetch subscription ID for AzureMachine %s/%s", m.Namespace, m.Name))
239+
//}
240240

241241
m.Spec.SetDataDisksDefaults()
242-
m.Spec.SetIdentityDefaults(subscriptionID)
242+
m.Spec.SetIdentityDefaults("")
243243
m.Spec.SetSpotEvictionPolicyDefaults()
244244
m.Spec.SetDiagnosticsDefaults()
245245
m.Spec.SetNetworkInterfacesDefaults()

api/v1beta1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,8 @@ type SubnetSpec struct {
759759
// +optional
760760
ID string `json:"id,omitempty"`
761761

762-
// Name defines a name for the subnet resource.
763-
Name string `json:"name"`
762+
//// Name defines a name for the subnet resource.
763+
//Name string `json:"name"`
764764

765765
// SecurityGroup defines the NSG (network security group) that should be attached to this subnet.
766766
// +optional

azure/services/loadbalancers/loadbalancers.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4"
2323

24-
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-02-01/network"
2524
"github.com/pkg/errors"
2625
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
2726
"sigs.k8s.io/cluster-api-provider-azure/azure"
@@ -91,18 +90,18 @@ func (s *Service) Reconcile(ctx context.Context) error {
9190
result = err
9291
}
9392
} else {
94-
loadBalancer, ok := lb.(network.LoadBalancer)
93+
loadBalancer, ok := lb.(armnetwork.LoadBalancer)
9594
if !ok {
9695
// Return out of loop since this would be an unexpected fatal error
97-
result = errors.Errorf("created resource %T is not a network.LoadBalancer", lb)
96+
result = errors.Errorf("created resource %T is not an armnetwork.LoadBalancer", lb)
9897
break
9998
}
10099
if lbSpec.ResourceName() == s.Scope.APIServerLB().Name {
101-
lbIPConfig := loadBalancer.FrontendIPConfigurations
102-
if (lbIPConfig != nil) && len(*lbIPConfig) > 0 &&
103-
(*lbIPConfig)[0].PrivateIPAddress != nil &&
104-
*(*lbIPConfig)[0].PrivateIPAddress != "" {
105-
s.Scope.APIServerLB().FrontendIPs[0].PrivateIPAddress = *(*lbIPConfig)[0].PrivateIPAddress
100+
lbIPConfig := loadBalancer.Properties.FrontendIPConfigurations
101+
if lbIPConfig != nil && len(lbIPConfig) > 0 &&
102+
lbIPConfig[0].Properties.PrivateIPAddress != nil &&
103+
*lbIPConfig[0].Properties.PrivateIPAddress != "" {
104+
s.Scope.APIServerLB().FrontendIPs[0].PrivateIPAddress = *lbIPConfig[0].Properties.PrivateIPAddress
106105
}
107106
}
108107

azure/services/subnets/subnets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
4545
scope.EXPECT().UpdateSubnetID("subnet", "id")
4646
scope.EXPECT().UpdateSubnetCIDRs("subnet", []string{"cidr"})
4747
subnet := &asonetworkv1.VirtualNetworksSubnet{
48-
Spec: asonetworkv1.VirtualNetworks_Subnet_Spec{
48+
Spec: asonetworkv1.VirtualNetworksSubnet_Spec{
4949
AzureName: "subnet",
5050
},
51-
Status: asonetworkv1.VirtualNetworks_Subnet_STATUS{
51+
Status: asonetworkv1.VirtualNetworksSubnet_STATUS{
5252
Id: ptr.To("id"),
5353
AddressPrefixes: []string{"cidr"},
5454
},

0 commit comments

Comments
 (0)