Skip to content

Commit 6912766

Browse files
committed
Allow multiple subnets in network status
1 parent d961508 commit 6912766

File tree

13 files changed

+108
-79
lines changed

13 files changed

+108
-79
lines changed

api/v1alpha5/conversion.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ func Convert_v1alpha5_Network_To_v1alpha7_NetworkStatusWithSubnets(in *Network,
267267
return err
268268
}
269269

270-
out.Subnet = (*infrav1.Subnet)(in.Subnet)
270+
if in.Subnet != nil {
271+
out.Subnets = []infrav1.Subnet{infrav1.Subnet(*in.Subnet)}
272+
}
271273
return nil
272274
}
273275

@@ -278,7 +280,10 @@ func Convert_v1alpha7_NetworkStatusWithSubnets_To_v1alpha5_Network(in *infrav1.N
278280
return err
279281
}
280282

281-
out.Subnet = (*Subnet)(in.Subnet)
283+
// Can only down-convert a single subnet
284+
if len(in.Subnets) > 0 {
285+
out.Subnet = (*Subnet)(&in.Subnets[0])
286+
}
282287
return nil
283288
}
284289

api/v1alpha6/conversion.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,9 @@ func Convert_v1alpha6_Network_To_v1alpha7_NetworkStatusWithSubnets(in *Network,
473473
return err
474474
}
475475

476-
out.Subnet = (*infrav1.Subnet)(in.Subnet)
476+
if in.Subnet != nil {
477+
out.Subnets = []infrav1.Subnet{infrav1.Subnet(*in.Subnet)}
478+
}
477479
return nil
478480
}
479481

@@ -484,7 +486,10 @@ func Convert_v1alpha7_NetworkStatusWithSubnets_To_v1alpha6_Network(in *infrav1.N
484486
return err
485487
}
486488

487-
out.Subnet = (*Subnet)(in.Subnet)
489+
// Can only down-convert a single subnet
490+
if len(in.Subnets) > 0 {
491+
out.Subnet = (*Subnet)(&in.Subnets[0])
492+
}
488493
return nil
489494
}
490495

api/v1alpha7/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ type NetworkStatus struct {
176176
type NetworkStatusWithSubnets struct {
177177
NetworkStatus `json:",inline"`
178178

179-
Subnet *Subnet `json:"subnet,omitempty"`
179+
// Subnets is a list of subnets associated with the default cluster network. Machines which use the default cluster network will get an address from all of these subnets.
180+
Subnets []Subnet `json:"subnets,omitempty"`
180181
}
181182

182183
// Subnet represents basic information about the associated OpenStack Neutron Subnet.

api/v1alpha7/zz_generated.deepcopy.go

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

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,25 +4526,30 @@ spec:
45264526
type: string
45274527
name:
45284528
type: string
4529-
subnet:
4530-
description: Subnet represents basic information about the associated
4531-
OpenStack Neutron Subnet.
4532-
properties:
4533-
cidr:
4534-
type: string
4535-
id:
4536-
type: string
4537-
name:
4538-
type: string
4539-
tags:
4540-
items:
4529+
subnets:
4530+
description: Subnets is a list of subnets associated with the
4531+
default cluster network. Machines which use the default cluster
4532+
network will get an address from all of these subnets.
4533+
items:
4534+
description: Subnet represents basic information about the associated
4535+
OpenStack Neutron Subnet.
4536+
properties:
4537+
cidr:
45414538
type: string
4542-
type: array
4543-
required:
4544-
- cidr
4545-
- id
4546-
- name
4547-
type: object
4539+
id:
4540+
type: string
4541+
name:
4542+
type: string
4543+
tags:
4544+
items:
4545+
type: string
4546+
type: array
4547+
required:
4548+
- cidr
4549+
- id
4550+
- name
4551+
type: object
4552+
type: array
45484553
tags:
45494554
items:
45504555
type: string

controllers/openstackcluster_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,13 @@ func reconcileNetworkComponents(scope scope.Scope, cluster *clusterv1.Cluster, o
473473
return err
474474
}
475475

476-
openStackCluster.Status.Network.Subnet = &infrav1.Subnet{
477-
ID: subnet.ID,
478-
Name: subnet.Name,
479-
CIDR: subnet.CIDR,
480-
Tags: subnet.Tags,
476+
openStackCluster.Status.Network.Subnets = []infrav1.Subnet{
477+
{
478+
ID: subnet.ID,
479+
Name: subnet.Name,
480+
CIDR: subnet.CIDR,
481+
Tags: subnet.Tags,
482+
},
481483
}
482484
} else {
483485
err := networkingService.ReconcileNetwork(openStackCluster, clusterName)

controllers/openstackmachine_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func getDefaultOpenStackCluster() *infrav1.OpenStackCluster {
5252
NetworkStatus: infrav1.NetworkStatus{
5353
ID: networkUUID,
5454
},
55-
Subnet: &infrav1.Subnet{
56-
ID: subnetUUID,
55+
Subnets: []infrav1.Subnet{
56+
{ID: subnetUUID},
5757
},
5858
},
5959
ControlPlaneSecurityGroup: &infrav1.SecurityGroup{ID: controlPlaneSecurityGroupUUID},

pkg/cloud/services/compute/instance.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ func (s *Service) normalizePortTarget(port *infrav1.PortOpts, openStackCluster *
5858
port.Network = &infrav1.NetworkFilter{
5959
ID: openStackCluster.Status.Network.ID,
6060
}
61-
port.FixedIPs = []infrav1.FixedIP{
62-
{
61+
for _, subnet := range openStackCluster.Status.Network.Subnets {
62+
port.FixedIPs = append(port.FixedIPs, infrav1.FixedIP{
6363
Subnet: &infrav1.SubnetFilter{
64-
ID: openStackCluster.Status.Network.Subnet.ID,
64+
ID: subnet.ID,
6565
},
66-
},
66+
})
6767
}
6868

6969
return nil
@@ -182,17 +182,20 @@ func (s *Service) constructPorts(openStackCluster *infrav1.OpenStackCluster, ins
182182

183183
// no networks or ports found in the spec, so create a port on the cluster network
184184
if len(ports) == 0 {
185-
ports = []infrav1.PortOpts{{
185+
port := infrav1.PortOpts{
186186
Network: &infrav1.NetworkFilter{
187187
ID: openStackCluster.Status.Network.ID,
188188
},
189-
FixedIPs: []infrav1.FixedIP{{
189+
Trunk: &instanceSpec.Trunk,
190+
}
191+
for _, subnet := range openStackCluster.Status.Network.Subnets {
192+
port.FixedIPs = append(port.FixedIPs, infrav1.FixedIP{
190193
Subnet: &infrav1.SubnetFilter{
191-
ID: openStackCluster.Status.Network.Subnet.ID,
194+
ID: subnet.ID,
192195
},
193-
}},
194-
Trunk: &instanceSpec.Trunk,
195-
}}
196+
})
197+
}
198+
ports = []infrav1.PortOpts{port}
196199
}
197200

198201
// trunk support is required if any port has trunk enabled

pkg/cloud/services/compute/instance_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ func getDefaultOpenStackCluster() *infrav1.OpenStackCluster {
246246
NetworkStatus: infrav1.NetworkStatus{
247247
ID: networkUUID,
248248
},
249-
Subnet: &infrav1.Subnet{
250-
ID: subnetUUID,
249+
Subnets: []infrav1.Subnet{
250+
{ID: subnetUUID},
251251
},
252252
},
253253
ControlPlaneSecurityGroup: &infrav1.SecurityGroup{ID: controlPlaneSecurityGroupUUID},
@@ -844,8 +844,8 @@ func TestService_normalizePorts(t *testing.T) {
844844
NetworkStatus: infrav1.NetworkStatus{
845845
ID: defaultNetworkID,
846846
},
847-
Subnet: &infrav1.Subnet{
848-
ID: defaultSubnetID,
847+
Subnets: []infrav1.Subnet{
848+
{ID: defaultSubnetID},
849849
},
850850
},
851851
},

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *Service) ReconcileLoadBalancer(openStackCluster *infrav1.OpenStackClust
7878
}
7979
}
8080

81-
lb, err := s.getOrCreateLoadBalancer(openStackCluster, loadBalancerName, openStackCluster.Status.Network.Subnet.ID, clusterName, fixedIPAddress, lbProvider)
81+
lb, err := s.getOrCreateLoadBalancer(openStackCluster, loadBalancerName, openStackCluster.Status.Network.Subnets[0].ID, clusterName, fixedIPAddress, lbProvider)
8282
if err != nil {
8383
return false, err
8484
}
@@ -247,8 +247,10 @@ func (s *Service) getOrUpdateAllowedCIDRS(openStackCluster *infrav1.OpenStackClu
247247
}
248248

249249
if openStackCluster.Status.Network != nil {
250-
if openStackCluster.Status.Network.Subnet.CIDR != "" {
251-
allowedCIDRs = append(allowedCIDRs, openStackCluster.Status.Network.Subnet.CIDR)
250+
for _, subnet := range openStackCluster.Status.Network.Subnets {
251+
if subnet.CIDR != "" {
252+
allowedCIDRs = append(allowedCIDRs, subnet.CIDR)
253+
}
252254
}
253255

254256
if len(openStackCluster.Status.Router.IPs) > 0 {
@@ -390,8 +392,8 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
390392
if openStackCluster.Status.Network == nil {
391393
return errors.New("network is not yet available in openStackCluster.Status")
392394
}
393-
if openStackCluster.Status.Network.Subnet == nil {
394-
return errors.New("network.Subnet is not yet available in openStackCluster.Status")
395+
if len(openStackCluster.Status.Network.Subnets) == 0 {
396+
return errors.New("network.Subnets are not yet available in openStackCluster.Status")
395397
}
396398
if openStackCluster.Status.APIServerLoadBalancer == nil {
397399
return errors.New("network.APIServerLoadBalancer is not yet available in openStackCluster.Status")

0 commit comments

Comments
 (0)