Skip to content

Commit 70bfdaf

Browse files
committed
OpenStackClusterSpec: ControlPlaneEndpoint->pointer
1 parent 9223883 commit 70bfdaf

18 files changed

+112
-38
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 az to deploy control plane to
165170
// +listType=set

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
@@ -5536,8 +5536,13 @@ spec:
55365536
type: array
55375537
x-kubernetes-list-type: set
55385538
controlPlaneEndpoint:
5539-
description: ControlPlaneEndpoint represents the endpoint used to
5540-
communicate with the control plane.
5539+
description: |-
5540+
ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
5541+
It is normally populated automatically by the OpenStackCluster
5542+
controller during cluster provisioning. If it is set on creation the
5543+
control plane endpoint will use the values set here in preference to
5544+
values set elsewhere.
5545+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.
55415546
properties:
55425547
host:
55435548
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
@@ -2968,8 +2968,13 @@ spec:
29682968
type: array
29692969
x-kubernetes-list-type: set
29702970
controlPlaneEndpoint:
2971-
description: ControlPlaneEndpoint represents the endpoint
2972-
used to communicate with the control plane.
2971+
description: |-
2972+
ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2973+
It is normally populated automatically by the OpenStackCluster
2974+
controller during cluster provisioning. If it is set on creation the
2975+
control plane endpoint will use the values set here in preference to
2976+
values set elsewhere.
2977+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.
29732978
properties:
29742979
host:
29752980
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
@@ -747,7 +747,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
747747
// Control plane endpoint is already set
748748
// Note that checking this here means that we don't re-execute any of
749749
// the branches below if the control plane endpoint is already set.
750-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
750+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
751751
host = openStackCluster.Spec.ControlPlaneEndpoint.Host
752752

753753
// API server load balancer is disabled, but floating IP is not. Create
@@ -774,7 +774,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
774774
return err
775775
}
776776

777-
openStackCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{
777+
openStackCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
778778
Host: host,
779779
Port: int32(apiServerPort),
780780
}
@@ -785,7 +785,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
785785
// getAPIServerPort returns the port to use for the API server based on the cluster spec.
786786
func getAPIServerPort(openStackCluster *infrav1.OpenStackCluster) int {
787787
switch {
788-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
788+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
789789
return int(openStackCluster.Spec.ControlPlaneEndpoint.Port)
790790
case openStackCluster.Spec.APIServerPort != nil:
791791
return *openStackCluster.Spec.APIServerPort

controllers/openstackcluster_controller_test.go

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

controllers/openstackmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
461461
} else if !pointer.BoolDeref(openStackCluster.Spec.DisableAPIServerFloatingIP, false) {
462462
var floatingIPAddress *string
463463
switch {
464-
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
464+
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
465465
floatingIPAddress = &openStackCluster.Spec.ControlPlaneEndpoint.Host
466466
case openStackCluster.Spec.APIServerFloatingIP != nil:
467467
floatingIPAddress = openStackCluster.Spec.APIServerFloatingIP

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>
@@ -2232,7 +2237,12 @@ sigs.k8s.io/cluster-api/api/v1beta1.APIEndpoint
22322237
</td>
22332238
<td>
22342239
<em>(Optional)</em>
2235-
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.</p>
2240+
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2241+
It is normally populated automatically by the OpenStackCluster
2242+
controller during cluster provisioning. If it is set on creation the
2243+
control plane endpoint will use the values set here in preference to
2244+
values set elsewhere.
2245+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.</p>
22362246
</td>
22372247
</tr>
22382248
<tr>
@@ -2805,7 +2815,12 @@ sigs.k8s.io/cluster-api/api/v1beta1.APIEndpoint
28052815
</td>
28062816
<td>
28072817
<em>(Optional)</em>
2808-
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.</p>
2818+
<p>ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
2819+
It is normally populated automatically by the OpenStackCluster
2820+
controller during cluster provisioning. If it is set on creation the
2821+
control plane endpoint will use the values set here in preference to
2822+
values set elsewhere.
2823+
ControlPlaneEndpoint cannot be modified after ControlPlaneEndpoint.Host has been set.</p>
28092824
</td>
28102825
</tr>
28112826
<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)