Skip to content

Commit 74510ef

Browse files
committed
OpenStackClusterSpec: ControlPlaneEndpoint->pointer
1 parent cfd7211 commit 74510ef

18 files changed

+119
-40
lines changed

api/v1alpha5/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestConvertFrom(t *testing.T) {
5151
},
5252
ObjectMeta: metav1.ObjectMeta{
5353
Annotations: map[string]string{
54-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"}},\"status\":{\"ready\":false}}",
54+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"}},\"status\":{\"ready\":false}}",
5555
},
5656
},
5757
},
@@ -72,7 +72,7 @@ func TestConvertFrom(t *testing.T) {
7272
},
7373
ObjectMeta: metav1.ObjectMeta{
7474
Annotations: map[string]string{
75-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"}}}}}",
75+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"identityRef\":{\"cloudName\":\"\",\"name\":\"\"}}}}}",
7676
},
7777
},
7878
},

api/v1alpha5/zz_generated.conversion.go

Lines changed: 2 additions & 2 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"reflect"
2121

2222
apiconversion "k8s.io/apimachinery/pkg/conversion"
23+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2324
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2425

2526
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
@@ -201,6 +202,10 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
201202
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
202203
}
203204

205+
if dst.ControlPlaneEndpoint == nil || *dst.ControlPlaneEndpoint == (clusterv1.APIEndpoint{}) {
206+
dst.ControlPlaneEndpoint = previous.ControlPlaneEndpoint
207+
}
208+
204209
optional.RestoreString(&previous.APIServerFloatingIP, &dst.APIServerFloatingIP)
205210
optional.RestoreString(&previous.APIServerFixedIP, &dst.APIServerFixedIP)
206211
optional.RestoreInt(&previous.APIServerPort, &dst.APIServerPort)
@@ -256,6 +261,10 @@ func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
256261
}
257262
}
258263

264+
if in.ControlPlaneEndpoint != (clusterv1.APIEndpoint{}) {
265+
out.ControlPlaneEndpoint = &in.ControlPlaneEndpoint
266+
}
267+
259268
out.IdentityRef.CloudName = in.CloudName
260269
if in.IdentityRef != nil {
261270
out.IdentityRef.Name = in.IdentityRef.Name
@@ -304,6 +313,10 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *i
304313
out.AllowAllInClusterTraffic = in.ManagedSecurityGroups.AllowAllInClusterTraffic
305314
}
306315

316+
if in.ControlPlaneEndpoint != nil {
317+
out.ControlPlaneEndpoint = *in.ControlPlaneEndpoint
318+
}
319+
307320
out.CloudName = in.IdentityRef.CloudName
308321
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
309322

api/v1alpha6/zz_generated.conversion.go

Lines changed: 2 additions & 2 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1alpha7
1818

1919
import (
2020
apiconversion "k8s.io/apimachinery/pkg/conversion"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2122
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2223

2324
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
@@ -203,6 +204,10 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
203204
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
204205
}
205206

207+
if dst.ControlPlaneEndpoint == nil || *dst.ControlPlaneEndpoint == (clusterv1.APIEndpoint{}) {
208+
dst.ControlPlaneEndpoint = previous.ControlPlaneEndpoint
209+
}
210+
206211
optional.RestoreString(&previous.APIServerFloatingIP, &dst.APIServerFloatingIP)
207212
optional.RestoreString(&previous.APIServerFixedIP, &dst.APIServerFixedIP)
208213
optional.RestoreInt(&previous.APIServerPort, &dst.APIServerPort)
@@ -258,6 +263,10 @@ func Convert_v1alpha7_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
258263
}
259264
}
260265

266+
if in.ControlPlaneEndpoint != (clusterv1.APIEndpoint{}) {
267+
out.ControlPlaneEndpoint = &in.ControlPlaneEndpoint
268+
}
269+
261270
out.IdentityRef.CloudName = in.CloudName
262271
if in.IdentityRef != nil {
263272
out.IdentityRef.Name = in.IdentityRef.Name
@@ -306,6 +315,10 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in *i
306315
out.AllowAllInClusterTraffic = in.ManagedSecurityGroups.AllowAllInClusterTraffic
307316
}
308317

318+
if in.ControlPlaneEndpoint != nil {
319+
out.ControlPlaneEndpoint = *in.ControlPlaneEndpoint
320+
}
321+
309322
out.CloudName = in.IdentityRef.CloudName
310323
out.IdentityRef = &OpenStackIdentityReference{Name: in.IdentityRef.Name}
311324

api/v1alpha7/zz_generated.conversion.go

Lines changed: 2 additions & 2 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,13 @@ type OpenStackClusterSpec struct {
158158
Tags []string `json:"tags,omitempty"`
159159

160160
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
161+
// It is normally populated automatically by the OpenStackCluster
162+
// controller during cluster provisioning. If it is set on creation the
163+
// control plane endpoint will use the values set here in preference to
164+
// values set elsewhere.
165+
// ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.
161166
// +optional
162-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
167+
ControlPlaneEndpoint *clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty"`
163168

164169
// ControlPlaneAvailabilityZones is the set of availability zones which
165170
// control plane machines may be deployed to.

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5537,8 +5537,13 @@ spec:
55375537
type: array
55385538
x-kubernetes-list-type: set
55395539
controlPlaneEndpoint:
5540-
description: ControlPlaneEndpoint represents the endpoint used to
5541-
communicate with the control plane.
5540+
description: |-
5541+
ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
5542+
It is normally populated automatically by the OpenStackCluster
5543+
controller during cluster provisioning. If it is set on creation the
5544+
control plane endpoint will use the values set here in preference to
5545+
values set elsewhere.
5546+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.
55425547
properties:
55435548
host:
55445549
description: The hostname on which the API server is serving.

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,8 +2969,13 @@ spec:
29692969
type: array
29702970
x-kubernetes-list-type: set
29712971
controlPlaneEndpoint:
2972-
description: ControlPlaneEndpoint represents the endpoint
2973-
used to communicate with the control plane.
2972+
description: |-
2973+
ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2974+
It is normally populated automatically by the OpenStackCluster
2975+
controller during cluster provisioning. If it is set on creation the
2976+
control plane endpoint will use the values set here in preference to
2977+
values set elsewhere.
2978+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.
29742979
properties:
29752980
host:
29762981
description: The hostname on which the API server is serving.

controllers/openstackcluster_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
742742
// Control plane endpoint is already set
743743
// Note that checking this here means that we don't re-execute any of
744744
// the branches below if the control plane endpoint is already set.
745-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
745+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
746746
host = openStackCluster.Spec.ControlPlaneEndpoint.Host
747747

748748
// API server load balancer is disabled, but floating IP is not. Create
@@ -769,7 +769,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
769769
return err
770770
}
771771

772-
openStackCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
772+
openStackCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
773773
Host: host,
774774
Port: int32(apiServerPort),
775775
}
@@ -780,7 +780,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
780780
// getAPIServerPort returns the port to use for the API server based on the cluster spec.
781781
func getAPIServerPort(openStackCluster *infrav1.OpenStackCluster) int {
782782
switch {
783-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
783+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
784784
return int(openStackCluster.Spec.ControlPlaneEndpoint.Port)
785785
case openStackCluster.Spec.APIServerPort != nil:
786786
return *openStackCluster.Spec.APIServerPort

controllers/openstackcluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ func Test_getAPIServerPort(t *testing.T) {
763763
name: "with a control plane endpoint",
764764
openStackCluster: &infrav1.OpenStackCluster{
765765
Spec: infrav1.OpenStackClusterSpec{
766-
ControlPlaneEndpoint: clusterv1.APIEndpoint{
766+
ControlPlaneEndpoint: &clusterv1.APIEndpoint{
767767
Host: "192.168.0.1",
768768
Port: 6444,
769769
},

controllers/openstackmachine_controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,15 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
459459
return ctrl.Result{}, fmt.Errorf("reconcile load balancer member: %w", err)
460460
}
461461
} else if !pointer.BoolDeref(openStackCluster.Spec.DisableAPIServerFloatingIP, false) {
462-
floatingIPAddress := openStackCluster.Spec.ControlPlaneEndpoint.Host
463-
if openStackCluster.Spec.APIServerFloatingIP != nil {
464-
floatingIPAddress = *openStackCluster.Spec.APIServerFloatingIP
462+
var floatingIPAddress string
463+
if openStackCluster.Spec.ControlPlaneEndpoint != nil {
464+
floatingIPAddress = openStackCluster.Spec.ControlPlaneEndpoint.Host
465465
}
466+
467+
if floatingIPAddress == "" {
468+
floatingIPAddress = pointer.StringDeref(openStackCluster.Spec.APIServerFloatingIP, "")
469+
}
470+
466471
fp, err := networkingService.GetOrCreateFloatingIP(openStackMachine, openStackCluster, clusterName, &floatingIPAddress)
467472
if err != nil {
468473
conditions.MarkFalse(openStackMachine, infrav1.APIServerIngressReadyCondition, infrav1.FloatingIPErrorReason, clusterv1.ConditionSeverityError, "Floating IP cannot be obtained or created: %v", err)

docs/book/src/api/v1beta1/api.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ sigs.k8s.io/cluster-api/api/v1beta1.APIEndpoint
338338
</td>
339339
<td>
340340
<em>(Optional)</em>
341-
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.</p>
341+
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
342+
It is normally populated automatically by the OpenStackCluster
343+
controller during cluster provisioning. If it is set on creation the
344+
control plane endpoint will use the values set here in preference to
345+
values set elsewhere.
346+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.</p>
342347
</td>
343348
</tr>
344349
<tr>
@@ -2233,7 +2238,12 @@ sigs.k8s.io/cluster-api/api/v1beta1.APIEndpoint
22332238
</td>
22342239
<td>
22352240
<em>(Optional)</em>
2236-
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.</p>
2241+
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2242+
It is normally populated automatically by the OpenStackCluster
2243+
controller during cluster provisioning. If it is set on creation the
2244+
control plane endpoint will use the values set here in preference to
2245+
values set elsewhere.
2246+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.</p>
22372247
</td>
22382248
</tr>
22392249
<tr>
@@ -2810,7 +2820,12 @@ sigs.k8s.io/cluster-api/api/v1beta1.APIEndpoint
28102820
</td>
28112821
<td>
28122822
<em>(Optional)</em>
2813-
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.</p>
2823+
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2824+
It is normally populated automatically by the OpenStackCluster
2825+
controller during cluster provisioning. If it is set on creation the
2826+
control plane endpoint will use the values set here in preference to
2827+
values set elsewhere.
2828+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.</p>
28142829
</td>
28152830
</tr>
28162831
<tr>

pkg/cloud/services/loadbalancer/loadbalancer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func getAPIServerVIPAddress(openStackCluster *infrav1.OpenStackCluster) (*string
157157
return openStackCluster.Spec.APIServerFixedIP, nil
158158

159159
// If we are using the VIP as the control plane endpoint, use any value explicitly set on the control plane endpoint
160-
case pointer.BoolDeref(openStackCluster.Spec.DisableAPIServerFloatingIP, false) && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
160+
case pointer.BoolDeref(openStackCluster.Spec.DisableAPIServerFloatingIP, false) && openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
161161
fixedIPAddress, err := lookupHost(openStackCluster.Spec.ControlPlaneEndpoint.Host)
162162
if err != nil {
163163
return nil, fmt.Errorf("lookup host: %w", err)
@@ -181,7 +181,7 @@ func getAPIServerFloatingIP(openStackCluster *infrav1.OpenStackCluster) (*string
181181
return openStackCluster.Spec.APIServerFloatingIP, nil
182182

183183
// An IP address is specified explicitly in the control plane endpoint
184-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
184+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
185185
floatingIPAddress, err := lookupHost(openStackCluster.Spec.ControlPlaneEndpoint.Host)
186186
if err != nil {
187187
return nil, fmt.Errorf("lookup host: %w", err)
@@ -518,12 +518,18 @@ func (s *Service) ReconcileLoadBalancerMember(openStackCluster *infrav1.OpenStac
518518
if openStackCluster.Status.APIServerLoadBalancer == nil {
519519
return errors.New("network.APIServerLoadBalancer is not yet available in openStackCluster.Status")
520520
}
521+
if openStackCluster.Spec.ControlPlaneEndpoint == nil || !openStackCluster.Spec.ControlPlaneEndpoint.IsValid() {
522+
return errors.New("ControlPlaneEndpoint is not yet set in openStackCluster.Spec")
523+
}
521524

522525
loadBalancerName := getLoadBalancerName(clusterName)
523526
s.scope.Logger().Info("Reconciling load balancer member", "loadBalancerName", loadBalancerName)
524527

525528
lbID := openStackCluster.Status.APIServerLoadBalancer.ID
526-
portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)}
529+
var portList []int
530+
if openStackCluster.Spec.ControlPlaneEndpoint != nil {
531+
portList = append(portList, int(openStackCluster.Spec.ControlPlaneEndpoint.Port))
532+
}
527533
if openStackCluster.Spec.APIServerLoadBalancer != nil {
528534
portList = append(portList, openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts...)
529535
}
@@ -656,7 +662,10 @@ func (s *Service) DeleteLoadBalancerMember(openStackCluster *infrav1.OpenStackCl
656662

657663
lbID := lb.ID
658664

659-
portList := []int{int(openStackCluster.Spec.ControlPlaneEndpoint.Port)}
665+
var portList []int
666+
if openStackCluster.Spec.ControlPlaneEndpoint != nil {
667+
portList = append(portList, int(openStackCluster.Spec.ControlPlaneEndpoint.Port))
668+
}
660669
if openStackCluster.Spec.APIServerLoadBalancer != nil {
661670
portList = append(portList, openStackCluster.Spec.APIServerLoadBalancer.AdditionalPorts...)
662671
}

0 commit comments

Comments
 (0)