Skip to content

Commit 470d30b

Browse files
committed
Cleanup APILoadBalancer
Enabled now defaults to true. Provider becomes optional.String.
1 parent 44d4732 commit 470d30b

18 files changed

+188
-44
lines changed

api/v1alpha5/zz_generated.conversion.go

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/openstackcluster_conversion.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
198198
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
199199
}
200200

201+
if dst.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer != nil {
202+
if dst.APIServerLoadBalancer.Enabled == nil || !*dst.APIServerLoadBalancer.Enabled {
203+
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
204+
}
205+
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)
206+
}
201207
if dst.APIServerLoadBalancer.IsZero() {
202208
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
203209
}

api/v1alpha6/zz_generated.conversion.go

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/openstackcluster_conversion.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
200200
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
201201
}
202202

203+
if dst.APIServerLoadBalancer != nil && previous.APIServerLoadBalancer != nil {
204+
if dst.APIServerLoadBalancer.Enabled == nil || !*dst.APIServerLoadBalancer.Enabled {
205+
dst.APIServerLoadBalancer.Enabled = previous.APIServerLoadBalancer.Enabled
206+
}
207+
optional.RestoreString(&previous.APIServerLoadBalancer.Provider, &dst.APIServerLoadBalancer.Provider)
208+
}
203209
if dst.APIServerLoadBalancer.IsZero() {
204210
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
205211
}

api/v1alpha7/zz_generated.conversion.go

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/openstackcluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type OpenStackClusterSpec struct {
9595
DisableExternalNetwork optional.Bool `json:"disableExternalNetwork,omitempty"`
9696

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

api/v1beta1/types.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"k8s.io/utils/pointer"
21+
2022
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2123
)
2224

@@ -605,22 +607,41 @@ type Bastion struct {
605607
}
606608

607609
type APIServerLoadBalancer struct {
608-
// Enabled defines whether a load balancer should be created.
609-
Enabled bool `json:"enabled,omitempty"`
610+
// Enabled defines whether a load balancer should be created. This value
611+
// defaults to true if an APIServerLoadBalancer is given.
612+
//
613+
// There is no reason to set this to false. To disable creation of the
614+
// API server loadbalancer, omit the APIServerLoadBalancer field in the
615+
// cluster spec instead.
616+
//
617+
// +kubebuilder:validation:Required
618+
// +kubebuilder:default:=true
619+
Enabled *bool `json:"enabled"`
620+
610621
// AdditionalPorts adds additional tcp ports to the load balancer.
622+
// +optional
623+
// +listType=set
611624
AdditionalPorts []int `json:"additionalPorts,omitempty"`
625+
612626
// AllowedCIDRs restrict access to all API-Server listeners to the given address CIDRs.
627+
// +optional
628+
// +listType=set
613629
AllowedCIDRs []string `json:"allowedCIDRs,omitempty"`
614-
// Octavia Provider Used to create load balancer
615-
Provider string `json:"provider,omitempty"`
630+
631+
// Provider specifies name of a specific Octavia provider to use for the
632+
// API load balancer. The Octavia default will be used if it is not
633+
// specified.
634+
// +optional
635+
Provider optional.String `json:"provider,omitempty"`
616636
}
617637

618638
func (s *APIServerLoadBalancer) IsZero() bool {
619-
return s == nil || (!s.Enabled && len(s.AdditionalPorts) == 0 && len(s.AllowedCIDRs) == 0 && s.Provider == "")
639+
return s == nil || ((s.Enabled == nil || !*s.Enabled) && len(s.AdditionalPorts) == 0 && len(s.AllowedCIDRs) == 0 && pointer.StringDeref(s.Provider, "") == "")
620640
}
621641

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

626647
// ReferencedMachineResources contains resolved references to resources required by the machine.

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4866,27 +4866,41 @@ spec:
48664866
apiServerLoadBalancer:
48674867
description: |-
48684868
APIServerLoadBalancer configures the optional LoadBalancer for the APIServer.
4869-
It must be activated by setting `enabled: true`.
4869+
If not specified, no load balancer will be created for the API server.
48704870
properties:
48714871
additionalPorts:
48724872
description: AdditionalPorts adds additional tcp ports to the
48734873
load balancer.
48744874
items:
48754875
type: integer
48764876
type: array
4877+
x-kubernetes-list-type: set
48774878
allowedCIDRs:
48784879
description: AllowedCIDRs restrict access to all API-Server listeners
48794880
to the given address CIDRs.
48804881
items:
48814882
type: string
48824883
type: array
4884+
x-kubernetes-list-type: set
48834885
enabled:
4884-
description: Enabled defines whether a load balancer should be
4885-
created.
4886+
default: true
4887+
description: |-
4888+
Enabled defines whether a load balancer should be created. This value
4889+
defaults to true if an APIServerLoadBalancer is given.
4890+
4891+
4892+
There is no reason to set this to false. To disable creation of the
4893+
API server loadbalancer, omit the APIServerLoadBalancer field in the
4894+
cluster spec instead.
48864895
type: boolean
48874896
provider:
4888-
description: Octavia Provider Used to create load balancer
4897+
description: |-
4898+
Provider specifies name of a specific Octavia provider to use for the
4899+
API load balancer. The Octavia default will be used if it is not
4900+
specified.
48894901
type: string
4902+
required:
4903+
- enabled
48904904
type: object
48914905
apiServerPort:
48924906
description: |-

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,27 +2290,41 @@ spec:
22902290
apiServerLoadBalancer:
22912291
description: |-
22922292
APIServerLoadBalancer configures the optional LoadBalancer for the APIServer.
2293-
It must be activated by setting `enabled: true`.
2293+
If not specified, no load balancer will be created for the API server.
22942294
properties:
22952295
additionalPorts:
22962296
description: AdditionalPorts adds additional tcp ports
22972297
to the load balancer.
22982298
items:
22992299
type: integer
23002300
type: array
2301+
x-kubernetes-list-type: set
23012302
allowedCIDRs:
23022303
description: AllowedCIDRs restrict access to all API-Server
23032304
listeners to the given address CIDRs.
23042305
items:
23052306
type: string
23062307
type: array
2308+
x-kubernetes-list-type: set
23072309
enabled:
2308-
description: Enabled defines whether a load balancer should
2309-
be created.
2310+
default: true
2311+
description: |-
2312+
Enabled defines whether a load balancer should be created. This value
2313+
defaults to true if an APIServerLoadBalancer is given.
2314+
2315+
2316+
There is no reason to set this to false. To disable creation of the
2317+
API server loadbalancer, omit the APIServerLoadBalancer field in the
2318+
cluster spec instead.
23102319
type: boolean
23112320
provider:
2312-
description: Octavia Provider Used to create load balancer
2321+
description: |-
2322+
Provider specifies name of a specific Octavia provider to use for the
2323+
API load balancer. The Octavia default will be used if it is not
2324+
specified.
23132325
type: string
2326+
required:
2327+
- enabled
23142328
type: object
23152329
apiServerPort:
23162330
description: |-

controllers/openstackcluster_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope
184184

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

187-
if openStackCluster.Spec.APIServerLoadBalancer != nil && openStackCluster.Spec.APIServerLoadBalancer.Enabled {
187+
if openStackCluster.Spec.APIServerLoadBalancer.IsEnabled() {
188188
loadBalancerService, err := loadbalancer.NewService(scope)
189189
if err != nil {
190190
return reconcile.Result{}, err
@@ -722,7 +722,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
722722
// API server load balancer is enabled. Create an Octavia load balancer.
723723
// Note that we reconcile the load balancer even if the control plane
724724
// endpoint is already set.
725-
case openStackCluster.Spec.APIServerLoadBalancer != nil && openStackCluster.Spec.APIServerLoadBalancer.Enabled:
725+
case openStackCluster.Spec.APIServerLoadBalancer.IsEnabled():
726726
loadBalancerService, err := loadbalancer.NewService(scope)
727727
if err != nil {
728728
return err

0 commit comments

Comments
 (0)