Skip to content

Commit

Permalink
Support BYO dual-stack Network
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
MaysaMacedo committed Dec 13, 2023
1 parent 85aed76 commit 98e4e82
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 21 deletions.
1 change: 1 addition & 0 deletions api/v1alpha5/zz_generated.conversion.go

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

1 change: 1 addition & 0 deletions api/v1alpha6/zz_generated.conversion.go

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

5 changes: 5 additions & 0 deletions api/v1alpha7/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ type OpenStackClusterSpec struct {
Network NetworkFilter `json:"network,omitempty"`

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

// If NodeCIDR cannot be set this can be used to detect existing IPv4 and/or IPv6 subnets.
Subnets []SubnetFilter `json:"subnets,omitempty"`

// NetworkMTU sets the maximum transmission unit (MTU) value to address fragmentation for the private network ID.
// This value will be used only if the Cluster actuator creates the network.
// If leaved empty, the network will have the default MTU defined in Openstack network service.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha7/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -4328,8 +4328,9 @@ spec:
type: string
type: object
subnet:
description: If NodeCIDR cannot be set this can be used to detect
an existing subnet.
description: "If NodeCIDR cannot be set this can be used to detect
an existing subnet. \n Deprecated: Use subnets instead. subnet will
be silently ignored if subnets is set."
properties:
cidr:
type: string
Expand Down Expand Up @@ -4358,6 +4359,39 @@ spec:
tagsAny:
type: string
type: object
subnets:
description: If NodeCIDR cannot be set this can be used to detect
existing IPv4 and/or IPv6 subnets.
items:
properties:
cidr:
type: string
description:
type: string
gateway_ip:
type: string
id:
type: string
ipVersion:
type: integer
ipv6AddressMode:
type: string
ipv6RaMode:
type: string
name:
type: string
notTags:
type: string
notTagsAny:
type: string
projectId:
type: string
tags:
type: string
tagsAny:
type: string
type: object
type: array
tags:
description: Tags for all resources in cluster
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2195,8 +2195,9 @@ spec:
type: string
type: object
subnet:
description: If NodeCIDR cannot be set this can be used to
detect an existing subnet.
description: "If NodeCIDR cannot be set this can be used to
detect an existing subnet. \n Deprecated: Use subnets instead.
subnet will be silently ignored if subnets is set."
properties:
cidr:
type: string
Expand Down Expand Up @@ -2225,6 +2226,39 @@ spec:
tagsAny:
type: string
type: object
subnets:
description: If NodeCIDR cannot be set this can be used to
detect existing IPv4 and/or IPv6 subnets.
items:
properties:
cidr:
type: string
description:
type: string
gateway_ip:
type: string
id:
type: string
ipVersion:
type: integer
ipv6AddressMode:
type: string
ipv6RaMode:
type: string
name:
type: string
notTags:
type: string
notTagsAny:
type: string
projectId:
type: string
tags:
type: string
tagsAny:
type: string
type: object
type: array
tags:
description: Tags for all resources in cluster
items:
Expand Down
34 changes: 17 additions & 17 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,26 +461,26 @@ func reconcileNetworkComponents(scope scope.Scope, cluster *clusterv1.Cluster, o
openStackCluster.Status.Network.Name = networkList[0].Name
openStackCluster.Status.Network.Tags = networkList[0].Tags

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

// Set the cluster to failed if subnet filter is invalid
if errors.Is(err, networking.ErrFilterMatch) {
handleUpdateOSCError(openStackCluster, err)
return err
}

return err
}

openStackCluster.Status.Network.Subnets = []infrav1.Subnet{
{
ID: subnet.ID,
Name: subnet.Name,
CIDR: subnet.CIDR,
Tags: subnet.Tags,
},
filteredSubnets = append(filteredSubnets, infrav1.Subnet{
ID: filteredSubnet.ID,
Name: filteredSubnet.Name,
CIDR: filteredSubnet.CIDR,
Tags: filteredSubnet.Tags,
})
}
openStackCluster.Status.Network.Subnets = filteredSubnets
} else {
err := networkingService.ReconcileNetwork(openStackCluster, clusterName)
if err != nil {
Expand Down

0 comments on commit 98e4e82

Please sign in to comment.