Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type NetworkDescriber interface {
IsVnetManaged() bool
NodeSubnet() infrav1.SubnetSpec
ControlPlaneSubnet() infrav1.SubnetSpec
SetSubnet(infrav1.SubnetSpec)
IsIPv6Enabled() bool
NodeRouteTable() infrav1.RouteTable
ControlPlaneRouteTable() infrav1.RouteTable
Expand Down
24 changes: 24 additions & 0 deletions azure/mocks/service_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ func (s *ClusterScope) NodeSubnet() infrav1.SubnetSpec {
return subnet
}

// SetSubnet sets the subnet spec for the subnet with the same role.
func (s *ClusterScope) SetSubnet(subnetSpec infrav1.SubnetSpec) {
for i, sn := range s.AzureCluster.Spec.NetworkSpec.Subnets {
if sn.Role == subnetSpec.Role {
s.AzureCluster.Spec.NetworkSpec.Subnets[i] = subnetSpec
return
}
}
}

// ControlPlaneRouteTable returns the cluster controlplane routetable.
func (s *ClusterScope) ControlPlaneRouteTable() infrav1.RouteTable {
subnet, _ := s.AzureCluster.Spec.NetworkSpec.GetControlPlaneSubnet()
Expand Down
6 changes: 6 additions & 0 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func (s *ManagedControlPlaneScope) NodeSubnet() infrav1.SubnetSpec {
}
}

// SetSubnet sets the passed subnet spec into the scope.
// This is not used when using a managed control plane.
func (s *ManagedControlPlaneScope) SetSubnet(subnetSpec infrav1.SubnetSpec) {
// no-op
}

// ControlPlaneSubnet returns the cluster control plane subnet.
func (s *ManagedControlPlaneScope) ControlPlaneSubnet() infrav1.SubnetSpec {
return infrav1.SubnetSpec{}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions azure/services/routetables/mock_routetables/routetables_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions azure/services/routetables/routetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
// currently don't support specifying your own routes via spec
routeTableSpec.Subnet.RouteTable.Name = to.String(existingRouteTable.Name)
routeTableSpec.Subnet.RouteTable.ID = to.String(existingRouteTable.ID)
s.Scope.SetSubnet(routeTableSpec.Subnet)

continue
}
Expand Down
16 changes: 16 additions & 0 deletions azure/services/routetables/routetables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,29 @@ func TestReconcileRouteTables(t *testing.T) {
Name: to.StringPtr("my-cp-routetable"),
ID: to.StringPtr("1"),
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
Name: "control-plane-subnet",
Role: infrav1.SubnetControlPlane,
RouteTable: infrav1.RouteTable{
ID: "1",
Name: "my-cp-routetable",
},
}).Times(1)
s.NodeSubnet().AnyTimes().Return(infrav1.SubnetSpec{Name: "node-subnet", Role: infrav1.SubnetNode})
s.NodeRouteTable().AnyTimes().Return(infrav1.RouteTable{Name: "my-node-routetable"})
s.ResourceGroup().AnyTimes().Return("my-rg")
m.Get(gomockinternal.AContext(), "my-rg", "my-node-routetable").Return(network.RouteTable{
Name: to.StringPtr("my-node-routetable"),
ID: to.StringPtr("2"),
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
Name: "node-subnet",
Role: infrav1.SubnetNode,
RouteTable: infrav1.RouteTable{
ID: "2",
Name: "my-node-routetable",
},
}).Times(1)
},
},
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions azure/services/subnets/mock_subnets/subnets_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions azure/services/subnets/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func (s *Service) Reconcile(ctx context.Context) error {
continue
}

subnet.Role = subnetSpec.Role
subnet.Name = existingSubnet.Name
subnet.CIDRBlocks = existingSubnet.CIDRBlocks
subnet.ID = existingSubnet.ID
subnet.CIDRBlocks = existingSubnet.CIDRBlocks

s.Scope.SetSubnet(subnet)

case !s.Scope.IsVnetManaged():
return fmt.Errorf("vnet was provided but subnet %s is missing", subnetSpec.Name)
Expand Down
24 changes: 24 additions & 0 deletions azure/services/subnets/subnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ func TestReconcileSubnets(t *testing.T) {
},
},
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
ID: "subnet-id",
Name: "my-subnet",
Role: infrav1.SubnetNode,
CIDRBlocks: []string{"10.0.0.0/16"},
}).Times(1)
m.Get(gomockinternal.AContext(), "", "my-vnet", "my-subnet-1").
Return(network.Subnet{
ID: to.StringPtr("subnet-id-1"),
Expand All @@ -252,6 +258,12 @@ func TestReconcileSubnets(t *testing.T) {
},
},
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
ID: "subnet-id-1",
Name: "my-subnet-1",
Role: infrav1.SubnetControlPlane,
CIDRBlocks: []string{"10.2.0.0/16"},
}).Times(1)
},
},
{
Expand Down Expand Up @@ -309,6 +321,12 @@ func TestReconcileSubnets(t *testing.T) {
},
},
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
ID: "subnet-id",
Name: "my-subnet",
Role: infrav1.SubnetNode,
CIDRBlocks: []string{"10.0.0.0/16", "2001:1234:5678:9abd::/64"},
}).Times(1)
m.Get(gomockinternal.AContext(), "", "my-vnet", "my-ipv6-subnet-cp").
Return(network.Subnet{
ID: to.StringPtr("subnet-id-1"),
Expand All @@ -328,6 +346,12 @@ func TestReconcileSubnets(t *testing.T) {
},
},
}, nil)
s.SetSubnet(infrav1.SubnetSpec{
ID: "subnet-id-1",
Name: "my-subnet-1",
Role: infrav1.SubnetControlPlane,
CIDRBlocks: []string{"10.2.0.0/16", "2001:1234:5678:9abc::/64"},
}).Times(1)
},
},
}
Expand Down