Skip to content

Commit bdd9f8c

Browse files
authored
Merge pull request #1401 from fiunchinho/fix-save-state-from-azure-api
Save subnet details back to scope
2 parents e101b68 + 4cff58a commit bdd9f8c

File tree

13 files changed

+145
-3
lines changed

13 files changed

+145
-3
lines changed

azure/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type NetworkDescriber interface {
6464
IsVnetManaged() bool
6565
NodeSubnet() infrav1.SubnetSpec
6666
ControlPlaneSubnet() infrav1.SubnetSpec
67+
SetSubnet(infrav1.SubnetSpec)
6768
IsIPv6Enabled() bool
6869
NodeRouteTable() infrav1.RouteTable
6970
ControlPlaneRouteTable() infrav1.RouteTable

azure/mocks/service_mock.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/scope/cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ func (s *ClusterScope) NodeSubnet() infrav1.SubnetSpec {
360360
return subnet
361361
}
362362

363+
// SetSubnet sets the subnet spec for the subnet with the same role.
364+
func (s *ClusterScope) SetSubnet(subnetSpec infrav1.SubnetSpec) {
365+
for i, sn := range s.AzureCluster.Spec.NetworkSpec.Subnets {
366+
if sn.Role == subnetSpec.Role {
367+
s.AzureCluster.Spec.NetworkSpec.Subnets[i] = subnetSpec
368+
return
369+
}
370+
}
371+
}
372+
363373
// ControlPlaneRouteTable returns the cluster controlplane routetable.
364374
func (s *ClusterScope) ControlPlaneRouteTable() infrav1.RouteTable {
365375
subnet, _ := s.AzureCluster.Spec.NetworkSpec.GetControlPlaneSubnet()

azure/scope/managedcontrolplane.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ func (s *ManagedControlPlaneScope) NodeSubnet() infrav1.SubnetSpec {
198198
}
199199
}
200200

201+
// SetSubnet sets the passed subnet spec into the scope.
202+
// This is not used when using a managed control plane.
203+
func (s *ManagedControlPlaneScope) SetSubnet(subnetSpec infrav1.SubnetSpec) {
204+
// no-op
205+
}
206+
201207
// ControlPlaneSubnet returns the cluster control plane subnet.
202208
func (s *ManagedControlPlaneScope) ControlPlaneSubnet() infrav1.SubnetSpec {
203209
return infrav1.SubnetSpec{}

azure/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/services/routetables/mock_routetables/routetables_mock.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

azure/services/routetables/routetables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
7272
// currently don't support specifying your own routes via spec
7373
routeTableSpec.Subnet.RouteTable.Name = to.String(existingRouteTable.Name)
7474
routeTableSpec.Subnet.RouteTable.ID = to.String(existingRouteTable.ID)
75+
s.Scope.SetSubnet(routeTableSpec.Subnet)
7576

7677
continue
7778
}

azure/services/routetables/routetables_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,29 @@ func TestReconcileRouteTables(t *testing.T) {
142142
Name: to.StringPtr("my-cp-routetable"),
143143
ID: to.StringPtr("1"),
144144
}, nil)
145+
s.SetSubnet(infrav1.SubnetSpec{
146+
Name: "control-plane-subnet",
147+
Role: infrav1.SubnetControlPlane,
148+
RouteTable: infrav1.RouteTable{
149+
ID: "1",
150+
Name: "my-cp-routetable",
151+
},
152+
}).Times(1)
145153
s.NodeSubnet().AnyTimes().Return(infrav1.SubnetSpec{Name: "node-subnet", Role: infrav1.SubnetNode})
146154
s.NodeRouteTable().AnyTimes().Return(infrav1.RouteTable{Name: "my-node-routetable"})
147155
s.ResourceGroup().AnyTimes().Return("my-rg")
148156
m.Get(gomockinternal.AContext(), "my-rg", "my-node-routetable").Return(network.RouteTable{
149157
Name: to.StringPtr("my-node-routetable"),
150158
ID: to.StringPtr("2"),
151159
}, nil)
160+
s.SetSubnet(infrav1.SubnetSpec{
161+
Name: "node-subnet",
162+
Role: infrav1.SubnetNode,
163+
RouteTable: infrav1.RouteTable{
164+
ID: "2",
165+
Name: "my-node-routetable",
166+
},
167+
}).Times(1)
152168
},
153169
},
154170
{

azure/services/securitygroups/mock_securitygroups/securitygroups_mock.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)