Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support to set allocation_pools for subnet #1847

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack
},
restorev1alpha8ClusterStatus,
),
"managedSubnets": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackCluster) *[]infrav1.SubnetSpec {
return &c.Spec.ManagedSubnets
},
),
}

func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down Expand Up @@ -322,6 +327,11 @@ var v1alpha8OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.O
},
restorev1alpha8ManagedSecurityGroups,
),
"managedSubnets": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackClusterTemplate) *[]infrav1.SubnetSpec {
return &c.Spec.Template.Spec.ManagedSubnets
},
),
}

func (r *OpenStackClusterTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down
13 changes: 13 additions & 0 deletions api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ func TestFuzzyConversion(t *testing.T) {
spec.CIDR = c.RandString()
}
},

func(pool *infrav1.AllocationPool, c fuzz.Continue) {
c.FuzzNoCustom(pool)

// Start and End are required properties, let's make sure both are set
for pool.Start == "" {
pool.Start = c.RandString()
}

for pool.End == "" {
pool.End = c.RandString()
}
},
}
}

Expand Down
13 changes: 13 additions & 0 deletions api/v1alpha7/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ func TestFuzzyConversion(t *testing.T) {
spec.CIDR = c.RandString()
}
},

func(pool *infrav1.AllocationPool, c fuzz.Continue) {
c.FuzzNoCustom(pool)

// Start and End are required properties, let's make sure both are set
for pool.Start == "" {
pool.Start = c.RandString()
}

for pool.End == "" {
pool.End = c.RandString()
}
},
}
}

Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha8/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,25 @@ type SubnetSpec struct {
// This field is required when defining a subnet.
// +required
CIDR string `json:"cidr"`

// DNSNameservers holds a list of DNS server addresses that will be provided when creating
// the subnet. These addresses need to have the same IP version as CIDR.
DNSNameservers []string `json:"dnsNameservers,omitempty"`

// AllocationPools is an array of AllocationPool objects that will be applied to OpenStack Subnet being created.
// If set, OpenStack will only allocate these IPs for Machines. It will still be possible to create ports from
// outside of these ranges manually.
AllocationPools []AllocationPool `json:"allocationPools,omitempty"`
}

type AllocationPool struct {
// Start represents the start of the AllocationPool, that is the lowest IP of the pool.
// +required
Start string `json:"start"`

// End represents the end of the AlloctionPool, that is the highest IP of the pool.
// +required
End string `json:"end"`
}

type PortOpts struct {
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha8/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 @@ -5537,6 +5537,26 @@ spec:
subnet is supported. If you leave this empty, no network will be created.
items:
properties:
allocationPools:
description: |-
AllocationPools is an array of AllocationPool objects that will be applied to OpenStack Subnet being created.
If set, OpenStack will only allocate these IPs for Machines. It will still be possible to create ports from
outside of these ranges manually.
items:
properties:
end:
description: End represents the end of the AlloctionPool,
that is the highest IP of the pool.
type: string
start:
description: Start represents the start of the AllocationPool,
that is the lowest IP of the pool.
type: string
required:
- end
- start
type: object
type: array
cidr:
description: |-
CIDR is representing the IP address range used to create the subnet, e.g. 10.0.0.0/24.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2972,6 +2972,27 @@ spec:
subnet is supported. If you leave this empty, no network will be created.
items:
properties:
allocationPools:
description: |-
AllocationPools is an array of AllocationPool objects that will be applied to OpenStack Subnet being created.
If set, OpenStack will only allocate these IPs for Machines. It will still be possible to create ports from
outside of these ranges manually.
items:
properties:
end:
description: End represents the end of the AlloctionPool,
that is the highest IP of the pool.
type: string
start:
description: Start represents the start of the
AllocationPool, that is the lowest IP of the
pool.
type: string
required:
- end
- start
type: object
type: array
cidr:
description: |-
CIDR is representing the IP address range used to create the subnet, e.g. 10.0.0.0/24.
Expand Down
4 changes: 4 additions & 0 deletions docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ In v1alpha8, this will be automatically converted to:

Please note that currently `managedSubnets` can only hold one element.

#### Addition of allocationPools

In v1alpha8, an `AllocationPools` property is introduced to `OpenStackCluster.Spec.ManagedSubnets`. When specified, OpenStack subnet created by CAPO will have the given values set as the `allocation_pools` property. This allows users to make sure OpenStack will not allocate some IP ranges in the subnet automatically. If the subnet is precreated and configured, CAPO will ignore `AllocationPools` property.

#### Change to managedSecurityGroups

The field `managedSecurityGroups` is now a pointer to a `ManagedSecurityGroups` object rather than a boolean.
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloud/services/networking/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ func (s *Service) createSubnet(openStackCluster *infrav1.OpenStackCluster, clust
Description: names.GetDescription(clusterName),
}

for _, pool := range openStackCluster.Spec.ManagedSubnets[0].AllocationPools {
opts.AllocationPools = append(opts.AllocationPools, subnets.AllocationPool{Start: pool.Start, End: pool.End})
}

subnet, err := s.client.CreateSubnet(opts)
if err != nil {
record.Warnf(openStackCluster, "FailedCreateSubnet", "Failed to create subnet %s: %v", name, err)
Expand Down
Loading