Skip to content

Commit 2c7b44b

Browse files
committed
OpenStackClusterSpec: APIServerFloatingIP, APIServerFixedIP, APIServerPort->optional
Affects go marshalling only.
1 parent e5d9630 commit 2c7b44b

18 files changed

+208
-97
lines changed

api/v1alpha5/conversion.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ func Convert_v1alpha5_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *O
291291
out.IdentityRef.Name = in.IdentityRef.Name
292292
}
293293

294+
// The generated conversion function converts "" to &"" which is not what we want
295+
if in.APIServerFloatingIP == "" {
296+
out.APIServerFloatingIP = nil
297+
}
298+
if in.APIServerFixedIP == "" {
299+
out.APIServerFixedIP = nil
300+
}
301+
302+
if in.APIServerPort != 0 {
303+
out.APIServerPort = pointer.Int(in.APIServerPort)
304+
}
305+
294306
return nil
295307
}
296308

api/v1alpha5/zz_generated.conversion.go

Lines changed: 18 additions & 6 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2626
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversion"
27+
optional "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2728
)
2829

2930
var _ ctrlconversion.Convertible = &OpenStackCluster{}
@@ -199,6 +200,10 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
199200
if dst.APIServerLoadBalancer.IsZero() {
200201
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
201202
}
203+
204+
optional.RestoreString(&previous.APIServerFloatingIP, &dst.APIServerFloatingIP)
205+
optional.RestoreString(&previous.APIServerFixedIP, &dst.APIServerFixedIP)
206+
optional.RestoreInt(&previous.APIServerPort, &dst.APIServerPort)
202207
}
203208

204209
func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s apiconversion.Scope) error {

api/v1alpha6/zz_generated.conversion.go

Lines changed: 18 additions & 6 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
2424
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/conversion"
25+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2526
)
2627

2728
var _ ctrlconversion.Convertible = &OpenStackCluster{}
@@ -201,6 +202,10 @@ func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infr
201202
if dst.APIServerLoadBalancer.IsZero() {
202203
dst.APIServerLoadBalancer = previous.APIServerLoadBalancer
203204
}
205+
206+
optional.RestoreString(&previous.APIServerFloatingIP, &dst.APIServerFloatingIP)
207+
optional.RestoreString(&previous.APIServerFixedIP, &dst.APIServerFixedIP)
208+
optional.RestoreInt(&previous.APIServerPort, &dst.APIServerPort)
204209
}
205210

206211
func Convert_v1alpha7_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s apiconversion.Scope) error {

api/v1alpha7/zz_generated.conversion.go

Lines changed: 18 additions & 6 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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2222
capierrors "sigs.k8s.io/cluster-api/errors"
23+
24+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2325
)
2426

2527
const (
@@ -116,7 +118,8 @@ type OpenStackClusterSpec struct {
116118
// The floatingIP will be created if it does not already exist.
117119
// If not specified, a new floatingIP is allocated.
118120
// This field is not used if DisableAPIServerFloatingIP is set to true.
119-
APIServerFloatingIP string `json:"apiServerFloatingIP,omitempty"`
121+
// +optional
122+
APIServerFloatingIP optional.String `json:"apiServerFloatingIP,omitempty"`
120123

121124
// APIServerFixedIP is the fixed IP which will be associated with the API server.
122125
// In the case where the API server has a floating IP but not a managed load balancer,
@@ -126,11 +129,13 @@ type OpenStackClusterSpec struct {
126129
// If a managed load balancer is not used AND the API server floating IP is disabled,
127130
// this field MUST be specified and should correspond to a pre-allocated port that
128131
// holds the fixed IP to be used as a VIP.
129-
APIServerFixedIP string `json:"apiServerFixedIP,omitempty"`
132+
// +optional
133+
APIServerFixedIP optional.String `json:"apiServerFixedIP,omitempty"`
130134

131135
// APIServerPort is the port on which the listener on the APIServer
132136
// will be created
133-
APIServerPort int `json:"apiServerPort,omitempty"`
137+
// +optional
138+
APIServerPort optional.Int `json:"apiServerPort,omitempty"`
134139

135140
// ManagedSecurityGroups determines whether OpenStack security groups for the cluster
136141
// will be managed by the OpenStack provider or whether pre-existing security groups will

api/v1beta1/zz_generated.deepcopy.go

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

controllers/openstackcluster_controller.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,14 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS
464464
return ctrl.Result{}, nil
465465
}
466466

467-
floatingIP := openStackCluster.Spec.Bastion.FloatingIP
468-
if openStackCluster.Status.Bastion.FloatingIP != "" {
467+
var floatingIP *string
468+
switch {
469+
case openStackCluster.Status.Bastion.FloatingIP != "":
469470
// Some floating IP has already been created for this bastion, make sure we re-use it
470-
floatingIP = openStackCluster.Status.Bastion.FloatingIP
471+
floatingIP = &openStackCluster.Status.Bastion.FloatingIP
472+
case openStackCluster.Spec.Bastion.FloatingIP != "":
473+
// Use floating IP from the spec
474+
floatingIP = &openStackCluster.Spec.Bastion.FloatingIP
471475
}
472476
// Check if there is an existing floating IP attached to bastion, in case where FloatingIP would not yet have been stored in cluster status
473477
fp, err = networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, floatingIP)
@@ -760,8 +764,8 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
760764
// plane floating IP. In this case we configure APIServerFixedIP as the
761765
// control plane endpoint and leave it to the user to configure load
762766
// balancing.
763-
case openStackCluster.Spec.APIServerFixedIP != "":
764-
host = openStackCluster.Spec.APIServerFixedIP
767+
case openStackCluster.Spec.APIServerFixedIP != nil:
768+
host = *openStackCluster.Spec.APIServerFixedIP
765769

766770
// Control plane endpoint is not set, and none can be created
767771
default:
@@ -783,8 +787,8 @@ func getAPIServerPort(openStackCluster *infrav1.OpenStackCluster) int {
783787
switch {
784788
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
785789
return int(openStackCluster.Spec.ControlPlaneEndpoint.Port)
786-
case openStackCluster.Spec.APIServerPort != 0:
787-
return openStackCluster.Spec.APIServerPort
790+
case openStackCluster.Spec.APIServerPort != nil:
791+
return *openStackCluster.Spec.APIServerPort
788792
}
789793
return 6443
790794
}

controllers/openstackcluster_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ var _ = Describe("OpenStackCluster controller", func() {
521521
Enabled: true,
522522
},
523523
DisableAPIServerFloatingIP: true,
524-
APIServerFixedIP: "10.0.0.1",
524+
APIServerFixedIP: pointer.String("10.0.0.1"),
525525
ExternalNetwork: &infrav1.NetworkFilter{
526526
ID: externalNetworkID,
527527
},
@@ -601,7 +601,7 @@ var _ = Describe("OpenStackCluster controller", func() {
601601
Enabled: true,
602602
},
603603
DisableAPIServerFloatingIP: true,
604-
APIServerFixedIP: "10.0.0.1",
604+
APIServerFixedIP: pointer.String("10.0.0.1"),
605605
ExternalNetwork: &infrav1.NetworkFilter{
606606
ID: externalNetworkID,
607607
},
@@ -683,7 +683,7 @@ var _ = Describe("OpenStackCluster controller", func() {
683683
testCluster.SetName("subnet-filtering")
684684
testCluster.Spec = infrav1.OpenStackClusterSpec{
685685
DisableAPIServerFloatingIP: true,
686-
APIServerFixedIP: "10.0.0.1",
686+
APIServerFixedIP: pointer.String("10.0.0.1"),
687687
DisableExternalNetwork: true,
688688
Subnets: []infrav1.SubnetFilter{
689689
{ID: clusterSubnetID},
@@ -777,7 +777,7 @@ func Test_getAPIServerPort(t *testing.T) {
777777
name: "with API server port",
778778
openStackCluster: &infrav1.OpenStackCluster{
779779
Spec: infrav1.OpenStackClusterSpec{
780-
APIServerPort: 6445,
780+
APIServerPort: pointer.Int(6445),
781781
},
782782
},
783783
want: 6445,

controllers/openstackmachine_controller.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cl
278278
} else if instanceStatus, err = computeService.GetInstanceStatusByName(openStackMachine, openStackMachine.Name); err != nil {
279279
return ctrl.Result{}, err
280280
}
281-
if !openStackCluster.Spec.APIServerLoadBalancer.IsEnabled() && util.IsControlPlaneMachine(machine) && openStackCluster.Spec.APIServerFloatingIP == "" {
281+
if !openStackCluster.Spec.APIServerLoadBalancer.IsEnabled() && util.IsControlPlaneMachine(machine) && openStackCluster.Spec.APIServerFloatingIP == nil {
282282
if instanceStatus != nil {
283283
instanceNS, err := instanceStatus.NetworkStatus()
284284
if err != nil {
@@ -459,14 +459,17 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
459459
return ctrl.Result{}, fmt.Errorf("reconcile load balancer member: %w", err)
460460
}
461461
} else if !openStackCluster.Spec.DisableAPIServerFloatingIP {
462-
floatingIPAddress := openStackCluster.Spec.ControlPlaneEndpoint.Host
463-
if openStackCluster.Spec.APIServerFloatingIP != "" {
462+
var floatingIPAddress *string
463+
switch {
464+
case openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
465+
floatingIPAddress = &openStackCluster.Spec.ControlPlaneEndpoint.Host
466+
case openStackCluster.Spec.APIServerFloatingIP != nil:
464467
floatingIPAddress = openStackCluster.Spec.APIServerFloatingIP
465468
}
466469
fp, err := networkingService.GetOrCreateFloatingIP(openStackMachine, openStackCluster, clusterName, floatingIPAddress)
467470
if err != nil {
468471
conditions.MarkFalse(openStackMachine, infrav1.APIServerIngressReadyCondition, infrav1.FloatingIPErrorReason, clusterv1.ConditionSeverityError, "Floating IP cannot be obtained or created: %v", err)
469-
return ctrl.Result{}, fmt.Errorf("get or create floating IP %q: %w", floatingIPAddress, err)
472+
return ctrl.Result{}, fmt.Errorf("get or create floating IP %v: %w", floatingIPAddress, err)
470473
}
471474
port, err := computeService.GetManagementPort(openStackCluster, instanceStatus)
472475
if err != nil {

0 commit comments

Comments
 (0)