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 654d714 commit 1b68d37
Show file tree
Hide file tree
Showing 15 changed files with 692 additions and 86 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.

47 changes: 45 additions & 2 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
}
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)

if previous.APIServerLoadBalancer.Network != nil {
dst.APIServerLoadBalancer.Network = previous.APIServerLoadBalancer.Network
}
if previous.APIServerLoadBalancer.Subnets != nil {
dst.APIServerLoadBalancer.Subnets = previous.APIServerLoadBalancer.Subnets
}
}
if dst.APIServerLoadBalancer.IsZero() {
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
Expand Down Expand Up @@ -287,6 +294,21 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
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_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *infrav1.OpenStackClusterSpec, out *OpenStackClusterSpec, s apiconversion.Scope) error {
err := autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in, out, s)
if err != nil {
Expand Down Expand Up @@ -373,6 +395,9 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
if previous.Bastion != nil && previous.Bastion.DependentResources.Ports != nil {
dst.Bastion.DependentResources.Ports = previous.Bastion.DependentResources.Ports
}
if previous.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer.LoadBalancerNetwork != nil {
dst.APIServerLoadBalancer.LoadBalancerNetwork = previous.APIServerLoadBalancer.LoadBalancerNetwork
}
}

func Convert_v1beta1_OpenStackClusterStatus_To_v1alpha6_OpenStackClusterStatus(in *infrav1.OpenStackClusterStatus, out *OpenStackClusterStatus, s apiconversion.Scope) error {
Expand All @@ -388,7 +413,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 @@ -403,7 +437,16 @@ 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
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/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
}
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)

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

if previous.APIServerLoadBalancer.Subnets != nil {
dst.APIServerLoadBalancer.Subnets = previous.APIServerLoadBalancer.Subnets
}
}
if dst.APIServerLoadBalancer.IsZero() {
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
Expand Down Expand Up @@ -289,6 +297,21 @@ func Convert_v1alpha7_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
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
}

func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in *infrav1.OpenStackClusterSpec, out *OpenStackClusterSpec, s apiconversion.Scope) error {
err := autoConvert_v1beta1_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in, out, s)
if err != nil {
Expand Down Expand Up @@ -358,6 +381,10 @@ func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *
if previous.Bastion != nil && previous.Bastion.DependentResources.Ports != nil {
dst.Bastion.DependentResources.Ports = previous.Bastion.DependentResources.Ports
}

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

func Convert_v1beta1_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(in *infrav1.OpenStackClusterStatus, out *OpenStackClusterStatus, s apiconversion.Scope) error {
Expand Down
Loading

0 comments on commit 1b68d37

Please sign in to comment.