Skip to content

Commit

Permalink
feat: add configurable loadbalancer network
Browse files Browse the repository at this point in the history
Previously when loadbalacer was created it used the same network/subnet as the
control plane nodes for the VIP. This was not always the right assumption as some
users might want to be able to customize this according to their env.

This commit fixes the above by adding two fields into
OpenStackClusterSpec/Status two fields `network` and `subnets` under
`APIServerLoadBalancer` so that user can define which network/subnet
to use for allocation of the loadbalancer.

Fixes: #1809

Signed-off-by: Ondrej Blazek <[email protected]>
  • Loading branch information
oblazek committed Mar 13, 2024
1 parent 23b9f34 commit cd7ab5b
Show file tree
Hide file tree
Showing 15 changed files with 689 additions and 87 deletions.
3 changes: 3 additions & 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.

51 changes: 49 additions & 2 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
if previous.Bastion != nil && previous.Bastion.DependentResources.PortsStatus != nil {
dst.Bastion.DependentResources.PortsStatus = previous.Bastion.DependentResources.PortsStatus
}

if previous.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer.LoadBalancerNetwork != nil {
dst.APIServerLoadBalancer.LoadBalancerNetwork = previous.APIServerLoadBalancer.LoadBalancerNetwork
}
}

func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
Expand Down Expand Up @@ -312,6 +316,11 @@ var v1beta1OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackC
return &c.Spec.ManagedSubnets
},
),
"apiServerLoadBalancer": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackCluster) *infrav1.APIServerLoadBalancer {
return &c.Spec.APIServerLoadBalancer
},
),
}

func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down Expand Up @@ -407,6 +416,11 @@ var v1beta1OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.Op
return &c.Spec.Template.Spec.ManagedSubnets
},
),
"apiServerLoadBalancer": conversion.UnconditionalFieldRestorer(
func(c *infrav1.OpenStackClusterTemplate) *infrav1.APIServerLoadBalancer {
return &c.Spec.Template.Spec.APIServerLoadBalancer
},
),
}

func (r *OpenStackClusterTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down Expand Up @@ -1014,7 +1028,16 @@ func Convert_v1beta1_OpenStackClusterStatus_To_v1alpha6_OpenStackClusterStatus(i
}

out.Network.Router = (*Router)(in.Router)
out.Network.APIServerLoadBalancer = (*LoadBalancer)(in.APIServerLoadBalancer)
if in.APIServerLoadBalancer != nil {
out.Network.APIServerLoadBalancer = &LoadBalancer{
Name: in.APIServerLoadBalancer.Name,
ID: in.APIServerLoadBalancer.ID,
IP: in.APIServerLoadBalancer.IP,
InternalIP: in.APIServerLoadBalancer.InternalIP,
AllowedCIDRs: in.APIServerLoadBalancer.AllowedCIDRs,
Tags: in.APIServerLoadBalancer.Tags,
}
}
}

return nil
Expand All @@ -1029,12 +1052,36 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1beta1_OpenStackClusterStatus(i
// Router and APIServerLoadBalancer have been moved out of Network in v1beta1
if in.Network != nil {
out.Router = (*infrav1.Router)(in.Network.Router)
out.APIServerLoadBalancer = (*infrav1.LoadBalancer)(in.Network.APIServerLoadBalancer)
if in.Network.APIServerLoadBalancer != nil {
out.APIServerLoadBalancer = &infrav1.LoadBalancer{
Name: in.Network.APIServerLoadBalancer.Name,
ID: in.Network.APIServerLoadBalancer.ID,
IP: in.Network.APIServerLoadBalancer.IP,
InternalIP: in.Network.APIServerLoadBalancer.InternalIP,
AllowedCIDRs: in.Network.APIServerLoadBalancer.AllowedCIDRs,
Tags: in.Network.APIServerLoadBalancer.Tags,
}
}
}

return nil
}

func Convert_v1beta1_APIServerLoadBalancer_To_v1alpha6_APIServerLoadBalancer(in *infrav1.APIServerLoadBalancer, out *APIServerLoadBalancer, s apiconversion.Scope) error {
return autoConvert_v1beta1_APIServerLoadBalancer_To_v1alpha6_APIServerLoadBalancer(in, out, s)
}

func Convert_v1beta1_LoadBalancer_To_v1alpha6_LoadBalancer(in *infrav1.LoadBalancer, out *LoadBalancer, s apiconversion.Scope) error {
return autoConvert_v1beta1_LoadBalancer_To_v1alpha6_LoadBalancer(in, out, s)
}

func Convert_v1alpha6_APIServerLoadBalancer_To_v1beta1_APIServerLoadBalancer(in *APIServerLoadBalancer, out *infrav1.APIServerLoadBalancer, s apiconversion.Scope) error {
err := autoConvert_v1alpha6_APIServerLoadBalancer_To_v1beta1_APIServerLoadBalancer(in, out, s)
out.Subnets = nil
out.Network = nil
return err
}

func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
err := autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
if err != nil {
Expand Down
48 changes: 18 additions & 30 deletions api/v1alpha6/zz_generated.conversion.go

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

27 changes: 27 additions & 0 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
if previous.Bastion != nil && previous.Bastion.DependentResources.PortsStatus != nil {
dst.Bastion.DependentResources.PortsStatus = previous.Bastion.DependentResources.PortsStatus
}

if previous.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer.LoadBalancerNetwork != nil {
dst.APIServerLoadBalancer.LoadBalancerNetwork = previous.APIServerLoadBalancer.LoadBalancerNetwork
}
}

var v1beta1OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{
Expand Down Expand Up @@ -401,6 +405,14 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
if previous.ManagedSecurityGroups != nil {
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
}

if previous.APIServerLoadBalancer.Network != nil {
dst.APIServerLoadBalancer.Network = previous.APIServerLoadBalancer.Network
}

if previous.APIServerLoadBalancer.Subnets != nil {
dst.APIServerLoadBalancer.Subnets = previous.APIServerLoadBalancer.Subnets
}
}

func (r *OpenStackCluster) ConvertTo(dstRaw ctrlconversion.Hub) error {
Expand Down Expand Up @@ -988,3 +1000,18 @@ func Convert_v1beta1_NetworkFilter_To_v1alpha7_NetworkFilter(in *infrav1.Network
infrav1.ConvertAllTagsFrom(&in.FilterByNeutronTags, &out.Tags, &out.TagsAny, &out.NotTags, &out.NotTagsAny)
return nil
}

func Convert_v1beta1_LoadBalancer_To_v1alpha7_LoadBalancer(in *infrav1.LoadBalancer, out *LoadBalancer, s apiconversion.Scope) error {
return autoConvert_v1beta1_LoadBalancer_To_v1alpha7_LoadBalancer(in, out, s)
}

func Convert_v1beta1_APIServerLoadBalancer_To_v1alpha7_APIServerLoadBalancer(in *infrav1.APIServerLoadBalancer, out *APIServerLoadBalancer, s apiconversion.Scope) error {
return autoConvert_v1beta1_APIServerLoadBalancer_To_v1alpha7_APIServerLoadBalancer(in, out, s)
}

func Convert_v1alpha7_APIServerLoadBalancer_To_v1beta1_APIServerLoadBalancer(in *APIServerLoadBalancer, out *infrav1.APIServerLoadBalancer, s apiconversion.Scope) error {
err := autoConvert_v1alpha7_APIServerLoadBalancer_To_v1beta1_APIServerLoadBalancer(in, out, s)
out.Subnets = nil
out.Network = nil
return err
}
Loading

0 comments on commit cd7ab5b

Please sign in to comment.