Skip to content

Commit 98e4e82

Browse files
committed
Support BYO dual-stack Network
This commit adds support to specify more than one existent subnet on the `OpenStackCluster`. The existent `OpenStackClusterSpec.Subnet` is deprecated in favor of `OpenStackClusterSpec.Subnets`.
1 parent 85aed76 commit 98e4e82

7 files changed

+101
-21
lines changed

api/v1alpha5/zz_generated.conversion.go

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

api/v1alpha6/zz_generated.conversion.go

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

api/v1alpha7/openstackcluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ type OpenStackClusterSpec struct {
4848
Network NetworkFilter `json:"network,omitempty"`
4949

5050
// If NodeCIDR cannot be set this can be used to detect an existing subnet.
51+
//
52+
// Deprecated: Use subnets instead. subnet will be silently ignored if subnets is set.
5153
Subnet SubnetFilter `json:"subnet,omitempty"`
5254

55+
// If NodeCIDR cannot be set this can be used to detect existing IPv4 and/or IPv6 subnets.
56+
Subnets []SubnetFilter `json:"subnets,omitempty"`
57+
5358
// NetworkMTU sets the maximum transmission unit (MTU) value to address fragmentation for the private network ID.
5459
// This value will be used only if the Cluster actuator creates the network.
5560
// If leaved empty, the network will have the default MTU defined in Openstack network service.

api/v1alpha7/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 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: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,8 +4328,9 @@ spec:
43284328
type: string
43294329
type: object
43304330
subnet:
4331-
description: If NodeCIDR cannot be set this can be used to detect
4332-
an existing subnet.
4331+
description: "If NodeCIDR cannot be set this can be used to detect
4332+
an existing subnet. \n Deprecated: Use subnets instead. subnet will
4333+
be silently ignored if subnets is set."
43334334
properties:
43344335
cidr:
43354336
type: string
@@ -4358,6 +4359,39 @@ spec:
43584359
tagsAny:
43594360
type: string
43604361
type: object
4362+
subnets:
4363+
description: If NodeCIDR cannot be set this can be used to detect
4364+
existing IPv4 and/or IPv6 subnets.
4365+
items:
4366+
properties:
4367+
cidr:
4368+
type: string
4369+
description:
4370+
type: string
4371+
gateway_ip:
4372+
type: string
4373+
id:
4374+
type: string
4375+
ipVersion:
4376+
type: integer
4377+
ipv6AddressMode:
4378+
type: string
4379+
ipv6RaMode:
4380+
type: string
4381+
name:
4382+
type: string
4383+
notTags:
4384+
type: string
4385+
notTagsAny:
4386+
type: string
4387+
projectId:
4388+
type: string
4389+
tags:
4390+
type: string
4391+
tagsAny:
4392+
type: string
4393+
type: object
4394+
type: array
43614395
tags:
43624396
description: Tags for all resources in cluster
43634397
items:

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,8 +2195,9 @@ spec:
21952195
type: string
21962196
type: object
21972197
subnet:
2198-
description: If NodeCIDR cannot be set this can be used to
2199-
detect an existing subnet.
2198+
description: "If NodeCIDR cannot be set this can be used to
2199+
detect an existing subnet. \n Deprecated: Use subnets instead.
2200+
subnet will be silently ignored if subnets is set."
22002201
properties:
22012202
cidr:
22022203
type: string
@@ -2225,6 +2226,39 @@ spec:
22252226
tagsAny:
22262227
type: string
22272228
type: object
2229+
subnets:
2230+
description: If NodeCIDR cannot be set this can be used to
2231+
detect existing IPv4 and/or IPv6 subnets.
2232+
items:
2233+
properties:
2234+
cidr:
2235+
type: string
2236+
description:
2237+
type: string
2238+
gateway_ip:
2239+
type: string
2240+
id:
2241+
type: string
2242+
ipVersion:
2243+
type: integer
2244+
ipv6AddressMode:
2245+
type: string
2246+
ipv6RaMode:
2247+
type: string
2248+
name:
2249+
type: string
2250+
notTags:
2251+
type: string
2252+
notTagsAny:
2253+
type: string
2254+
projectId:
2255+
type: string
2256+
tags:
2257+
type: string
2258+
tagsAny:
2259+
type: string
2260+
type: object
2261+
type: array
22282262
tags:
22292263
description: Tags for all resources in cluster
22302264
items:

controllers/openstackcluster_controller.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -461,26 +461,26 @@ func reconcileNetworkComponents(scope scope.Scope, cluster *clusterv1.Cluster, o
461461
openStackCluster.Status.Network.Name = networkList[0].Name
462462
openStackCluster.Status.Network.Tags = networkList[0].Tags
463463

464-
subnet, err := networkingService.GetNetworkSubnetByFilter(openStackCluster.Status.Network.ID, &openStackCluster.Spec.Subnet)
465-
if err != nil {
466-
err = fmt.Errorf("failed to find subnet: %w", err)
464+
var filteredSubnets []infrav1.Subnet
465+
for _, subnet := range openStackCluster.Spec.Subnets {
466+
filteredSubnet, err := networkingService.GetNetworkSubnetByFilter(openStackCluster.Status.Network.ID, &subnet)
467+
if err != nil {
468+
err = fmt.Errorf("failed to find subnet: %w", err)
469+
// Set the cluster to failed if subnet filter is invalid
470+
if errors.Is(err, networking.ErrFilterMatch) {
471+
handleUpdateOSCError(openStackCluster, err)
472+
}
467473

468-
// Set the cluster to failed if subnet filter is invalid
469-
if errors.Is(err, networking.ErrFilterMatch) {
470-
handleUpdateOSCError(openStackCluster, err)
474+
return err
471475
}
472-
473-
return err
474-
}
475-
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-
},
476+
filteredSubnets = append(filteredSubnets, infrav1.Subnet{
477+
ID: filteredSubnet.ID,
478+
Name: filteredSubnet.Name,
479+
CIDR: filteredSubnet.CIDR,
480+
Tags: filteredSubnet.Tags,
481+
})
483482
}
483+
openStackCluster.Status.Network.Subnets = filteredSubnets
484484
} else {
485485
err := networkingService.ReconcileNetwork(openStackCluster, clusterName)
486486
if err != nil {

0 commit comments

Comments
 (0)