Skip to content

Commit bb49edb

Browse files
MaysaMacedoEmilienM
authored andcommitted
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 3ceeeae commit bb49edb

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
@@ -5371,8 +5371,9 @@ spec:
53715371
type: string
53725372
type: object
53735373
subnet:
5374-
description: If NodeCIDR cannot be set this can be used to detect
5375-
an existing subnet.
5374+
description: "If NodeCIDR cannot be set this can be used to detect
5375+
an existing subnet. \n Deprecated: Use subnets instead. subnet will
5376+
be silently ignored if subnets is set."
53765377
properties:
53775378
cidr:
53785379
type: string
@@ -5401,6 +5402,39 @@ spec:
54015402
tagsAny:
54025403
type: string
54035404
type: object
5405+
subnets:
5406+
description: If NodeCIDR cannot be set this can be used to detect
5407+
existing IPv4 and/or IPv6 subnets.
5408+
items:
5409+
properties:
5410+
cidr:
5411+
type: string
5412+
description:
5413+
type: string
5414+
gateway_ip:
5415+
type: string
5416+
id:
5417+
type: string
5418+
ipVersion:
5419+
type: integer
5420+
ipv6AddressMode:
5421+
type: string
5422+
ipv6RaMode:
5423+
type: string
5424+
name:
5425+
type: string
5426+
notTags:
5427+
type: string
5428+
notTagsAny:
5429+
type: string
5430+
projectId:
5431+
type: string
5432+
tags:
5433+
type: string
5434+
tagsAny:
5435+
type: string
5436+
type: object
5437+
type: array
54045438
tags:
54055439
description: Tags for all resources in cluster
54065440
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
@@ -2924,8 +2924,9 @@ spec:
29242924
type: string
29252925
type: object
29262926
subnet:
2927-
description: If NodeCIDR cannot be set this can be used to
2928-
detect an existing subnet.
2927+
description: "If NodeCIDR cannot be set this can be used to
2928+
detect an existing subnet. \n Deprecated: Use subnets instead.
2929+
subnet will be silently ignored if subnets is set."
29292930
properties:
29302931
cidr:
29312932
type: string
@@ -2954,6 +2955,39 @@ spec:
29542955
tagsAny:
29552956
type: string
29562957
type: object
2958+
subnets:
2959+
description: If NodeCIDR cannot be set this can be used to
2960+
detect existing IPv4 and/or IPv6 subnets.
2961+
items:
2962+
properties:
2963+
cidr:
2964+
type: string
2965+
description:
2966+
type: string
2967+
gateway_ip:
2968+
type: string
2969+
id:
2970+
type: string
2971+
ipVersion:
2972+
type: integer
2973+
ipv6AddressMode:
2974+
type: string
2975+
ipv6RaMode:
2976+
type: string
2977+
name:
2978+
type: string
2979+
notTags:
2980+
type: string
2981+
notTagsAny:
2982+
type: string
2983+
projectId:
2984+
type: string
2985+
tags:
2986+
type: string
2987+
tagsAny:
2988+
type: string
2989+
type: object
2990+
type: array
29572991
tags:
29582992
description: Tags for all resources in cluster
29592993
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)