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

⚠️ Cleanup APILoadBalancer #1937

Merged
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
15 changes: 10 additions & 5 deletions api/v1alpha5/zz_generated.conversion.go

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

6 changes: 6 additions & 0 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
}

if dst.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer != nil {
if dst.APIServerLoadBalancer.Enabled == nil || !*dst.APIServerLoadBalancer.Enabled {
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
}
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)
}
if dst.APIServerLoadBalancer.IsZero() {
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
}
Expand Down
23 changes: 16 additions & 7 deletions api/v1alpha6/zz_generated.conversion.go

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

6 changes: 6 additions & 0 deletions api/v1alpha7/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
}

if dst.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer != nil {
if dst.APIServerLoadBalancer.Enabled == nil || !*dst.APIServerLoadBalancer.Enabled {
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
}
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)
}
if dst.APIServerLoadBalancer.IsZero() {
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
}
Expand Down
16 changes: 12 additions & 4 deletions api/v1alpha7/zz_generated.conversion.go

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

2 changes: 1 addition & 1 deletion api/v1beta1/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type OpenStackClusterSpec struct {
DisableExternalNetwork optional.Bool `json:"disableExternalNetwork,omitempty"`

// APIServerLoadBalancer configures the optional LoadBalancer for the APIServer.
// It must be activated by setting `enabled: true`.
// If not specified, no load balancer will be created for the API server.
// +optional
APIServerLoadBalancer *APIServerLoadBalancer `json:"apiServerLoadBalancer,omitempty"`

Expand Down
33 changes: 27 additions & 6 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1beta1

import (
"k8s.io/utils/pointer"

"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
)

Expand Down Expand Up @@ -605,22 +607,41 @@ type Bastion struct {
}

type APIServerLoadBalancer struct {
// Enabled defines whether a load balancer should be created.
Enabled bool `json:"enabled,omitempty"`
// Enabled defines whether a load balancer should be created. This value
// defaults to true if an APIServerLoadBalancer is given.
//
// There is no reason to set this to false. To disable creation of the
// API server loadbalancer, omit the APIServerLoadBalancer field in the
// cluster spec instead.
//
// +kubebuilder:validation:Required
// +kubebuilder:default:=true
Enabled *bool `json:"enabled"`

// AdditionalPorts adds additional tcp ports to the load balancer.
// +optional
// +listType=set
AdditionalPorts []int `json:"additionalPorts,omitempty"`

// AllowedCIDRs restrict access to all API-Server listeners to the given address CIDRs.
// +optional
// +listType=set
AllowedCIDRs []string `json:"allowedCIDRs,omitempty"`
// Octavia Provider Used to create load balancer
Provider string `json:"provider,omitempty"`

// Provider specifies name of a specific Octavia provider to use for the
// API load balancer. The Octavia default will be used if it is not
// specified.
// +optional
Provider optional.String `json:"provider,omitempty"`
}

func (s *APIServerLoadBalancer) IsZero() bool {
return s == nil || (!s.Enabled && len(s.AdditionalPorts) == 0 && len(s.AllowedCIDRs) == 0 && s.Provider == "")
return s == nil || ((s.Enabled == nil || !*s.Enabled) && len(s.AdditionalPorts) == 0 && len(s.AllowedCIDRs) == 0 && pointer.StringDeref(s.Provider, "") == "")
}

func (s *APIServerLoadBalancer) IsEnabled() bool {
return s != nil && s.Enabled
// The CRD default value for Enabled is true, so if the field is nil, it should be considered as true.
return s != nil && (s.Enabled == nil || *s.Enabled)
}

// ReferencedMachineResources contains resolved references to resources required by the machine.
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/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 @@ -4866,27 +4866,41 @@ spec:
apiServerLoadBalancer:
description: |-
APIServerLoadBalancer configures the optional LoadBalancer for the APIServer.
It must be activated by setting `enabled: true`.
If not specified, no load balancer will be created for the API server.
properties:
additionalPorts:
description: AdditionalPorts adds additional tcp ports to the
load balancer.
items:
type: integer
type: array
x-kubernetes-list-type: set
allowedCIDRs:
description: AllowedCIDRs restrict access to all API-Server listeners
to the given address CIDRs.
items:
type: string
type: array
x-kubernetes-list-type: set
enabled:
description: Enabled defines whether a load balancer should be
created.
default: true
description: |-
Enabled defines whether a load balancer should be created. This value
defaults to true if an APIServerLoadBalancer is given.


There is no reason to set this to false. To disable creation of the
API server loadbalancer, omit the APIServerLoadBalancer field in the
cluster spec instead.
type: boolean
provider:
description: Octavia Provider Used to create load balancer
description: |-
Provider specifies name of a specific Octavia provider to use for the
API load balancer. The Octavia default will be used if it is not
specified.
type: string
required:
- enabled
type: object
apiServerPort:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2290,27 +2290,41 @@ spec:
apiServerLoadBalancer:
description: |-
APIServerLoadBalancer configures the optional LoadBalancer for the APIServer.
It must be activated by setting `enabled: true`.
If not specified, no load balancer will be created for the API server.
properties:
additionalPorts:
description: AdditionalPorts adds additional tcp ports
to the load balancer.
items:
type: integer
type: array
x-kubernetes-list-type: set
allowedCIDRs:
description: AllowedCIDRs restrict access to all API-Server
listeners to the given address CIDRs.
items:
type: string
type: array
x-kubernetes-list-type: set
enabled:
description: Enabled defines whether a load balancer should
be created.
default: true
description: |-
Enabled defines whether a load balancer should be created. This value
defaults to true if an APIServerLoadBalancer is given.


There is no reason to set this to false. To disable creation of the
API server loadbalancer, omit the APIServerLoadBalancer field in the
cluster spec instead.
type: boolean
provider:
description: Octavia Provider Used to create load balancer
description: |-
Provider specifies name of a specific Octavia provider to use for the
API load balancer. The Octavia default will be used if it is not
specified.
type: string
required:
- enabled
type: object
apiServerPort:
description: |-
Expand Down
4 changes: 2 additions & 2 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope

clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)

if openStackCluster.Spec.APIServerLoadBalancer != nil && openStackCluster.Spec.APIServerLoadBalancer.Enabled {
if openStackCluster.Spec.APIServerLoadBalancer.IsEnabled() {
loadBalancerService, err := loadbalancer.NewService(scope)
if err != nil {
return reconcile.Result{}, err
Expand Down Expand Up @@ -722,7 +722,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
// API server load balancer is enabled. Create an Octavia load balancer.
// Note that we reconcile the load balancer even if the control plane
// endpoint is already set.
case openStackCluster.Spec.APIServerLoadBalancer != nil && openStackCluster.Spec.APIServerLoadBalancer.Enabled:
case openStackCluster.Spec.APIServerLoadBalancer.IsEnabled():
loadBalancerService, err := loadbalancer.NewService(scope)
if err != nil {
return err
Expand Down
Loading