Skip to content

Commit cb19c0d

Browse files
committed
fix network & fip setup
1 parent 6e9975e commit cb19c0d

7 files changed

Lines changed: 46 additions & 51 deletions

File tree

api/v1beta2/cloudscalecluster_types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,9 @@ type CloudscaleClusterStatus struct {
224224
// +optional
225225
Networks []NetworkStatus `json:"networks,omitempty"`
226226

227-
// FloatingIPHREF is the cloudscale.ch floating IP HREF.
228-
// The cloudscale API identifies floating IPs by HREF (e.g. "/v1/floating-ips/192.0.2.0/32"),
229-
// not by UUID like other resources.
227+
// FloatingIP is the cloudscale.ch floating IP.
230228
// +optional
231-
FloatingIPHREF string `json:"floatingIPHREF,omitempty"`
229+
FloatingIP string `json:"floatingIP,omitempty"`
232230

233231
// LoadBalancerID is the cloudscale.ch load balancer UUID.
234232
// +optional

api/v1beta2/condition_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ const (
6868
// FloatingIPProvisionedReason indicates the floating IP has been successfully provisioned and assigned.
6969
FloatingIPProvisionedReason = "FloatingIPProvisioned"
7070

71-
// FloatingIPNotReadyReason indicates the floating IP exists but is not yet assigned.
72-
FloatingIPNotReadyReason = "FloatingIPNotReady"
73-
7471
// FloatingIPDisabledReason indicates no floating IP is configured.
7572
FloatingIPDisabledReason = "FloatingIPDisabled"
7673

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,8 @@ spec:
323323
x-kubernetes-list-map-keys:
324324
- type
325325
x-kubernetes-list-type: map
326-
floatingIPHREF:
327-
description: |-
328-
FloatingIPHREF is the cloudscale.ch floating IP HREF.
329-
The cloudscale API identifies floating IPs by HREF (e.g. "/v1/floating-ips/192.0.2.0/32"),
330-
not by UUID like other resources.
326+
floatingIP:
327+
description: FloatingIP is the cloudscale.ch floating IP.
331328
type: string
332329
initialization:
333330
description: Initialization contains v1beta2 initialization tracking.

internal/controller/cloudscalecluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (r *CloudscaleClusterReconciler) isInfrastructureProvisioned(clusterScope *
222222

223223
// Floating IP must be provisioned if configured
224224
if clusterScope.CloudscaleCluster.Spec.FloatingIP != nil {
225-
if clusterScope.CloudscaleCluster.Status.FloatingIPHREF == "" {
225+
if clusterScope.CloudscaleCluster.Status.FloatingIP == "" {
226226
return false
227227
}
228228
}

internal/controller/cloudscalecluster_floatingip.go

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/utils/ptr"
2727
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
29+
logf "sigs.k8s.io/controller-runtime/pkg/log"
2930

3031
infrastructurev1beta2 "github.com/cloudscale-ch/cluster-api-provider-cloudscale/api/v1beta2"
3132
"github.com/cloudscale-ch/cluster-api-provider-cloudscale/internal/cloudscale"
@@ -41,13 +42,9 @@ func (r *CloudscaleClusterReconciler) reconcileFloatingIP(ctx context.Context, c
4142
return nil
4243
}
4344

44-
var fipPending bool
45-
4645
defer func() {
4746
if reterr != nil {
4847
r.setCondition(clusterScope, infrastructurev1beta2.FloatingIPReadyCondition, metav1.ConditionFalse, infrastructurev1beta2.FloatingIPErrorReason, reterr.Error())
49-
} else if fipPending {
50-
r.setCondition(clusterScope, infrastructurev1beta2.FloatingIPReadyCondition, metav1.ConditionFalse, infrastructurev1beta2.FloatingIPNotReadyReason, "Waiting for floating IP target")
5148
} else {
5249
r.setCondition(clusterScope, infrastructurev1beta2.FloatingIPReadyCondition, metav1.ConditionTrue, infrastructurev1beta2.FloatingIPProvisionedReason, "")
5350
}
@@ -59,15 +56,14 @@ func (r *CloudscaleClusterReconciler) reconcileFloatingIP(ctx context.Context, c
5956
}
6057

6158
// Managed floating IP: create if needed, then assign
62-
var err error
63-
fipPending, err = r.reconcileManagedFloatingIP(ctx, clusterScope, fipSpec)
59+
err := r.reconcileManagedFloatingIP(ctx, clusterScope, fipSpec)
6460
return err
6561
}
6662

6763
func (r *CloudscaleClusterReconciler) reconcileBYOFloatingIP(ctx context.Context, clusterScope *scope.ClusterScope, uuid string) error {
6864
// Cached: status + endpoint already populated from a prior reconcile.
6965
// BYO FIPs are immutable from CAPCS' perspective, so no need to refetch.
70-
if clusterScope.CloudscaleCluster.Status.FloatingIPHREF != "" &&
66+
if clusterScope.CloudscaleCluster.Status.FloatingIP != "" &&
7167
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host != "" {
7268
return nil
7369
}
@@ -77,34 +73,37 @@ func (r *CloudscaleClusterReconciler) reconcileBYOFloatingIP(ctx context.Context
7773
return fmt.Errorf("getting BYO floating IP %s: %w", uuid, err)
7874
}
7975

80-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = fip.HREF
76+
clusterScope.CloudscaleCluster.Status.FloatingIP = fip.IP()
8177
r.setControlPlaneEndpointFromFIP(clusterScope, fip)
8278
return nil
8379
}
8480

85-
func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Context, clusterScope *scope.ClusterScope, fipSpec *infrastructurev1beta2.FloatingIPSpec) (pending bool, _ error) {
81+
func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Context, clusterScope *scope.ClusterScope, fipSpec *infrastructurev1beta2.FloatingIPSpec) error {
82+
logger := logf.FromContext(ctx)
8683
tags := clusterOwnershipTags(clusterScope.CloudscaleCluster)
8784

85+
logger.Info("reconcile managed floating IP")
86+
8887
// Check if the floating IP already exists (by status ID or by tags)
8988
fip, id, err := ensureResource(ctx, clusterScope,
90-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF,
89+
clusterScope.CloudscaleCluster.Status.FloatingIP,
9190
"floating IP",
9291
clusterScope.CloudscaleClient.FloatingIPs,
93-
func(fip cloudscalesdk.FloatingIP) string { return fip.HREF },
92+
func(fip cloudscalesdk.FloatingIP) string { return fip.IP() },
9493
tags,
9594
)
9695
if err != nil {
97-
return false, err
96+
return err
9897
}
99-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = id
98+
clusterScope.CloudscaleCluster.Status.FloatingIP = id
10099

101100
if id != "" {
102101
// Existing floating IP: ensure it's assigned to the right target and set endpoint
103102
if err := r.ensureFloatingIPAssignment(ctx, clusterScope, fip); err != nil {
104-
return false, err
103+
return err
105104
}
106105
r.setControlPlaneEndpointFromFIP(clusterScope, fip)
107-
return false, nil
106+
return nil
108107
}
109108

110109
// Create new floating IP
@@ -126,8 +125,7 @@ func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Con
126125
// Assign to LB or CP server
127126
target, err := r.getFloatingIPTarget(ctx, clusterScope)
128127
if err != nil {
129-
// No target available yet (LB or CP server not ready)
130-
return true, nil
128+
logger.Info("no target available yet", "err", err)
131129
}
132130
if target.lbUUID != "" {
133131
req.LoadBalancer = target.lbUUID
@@ -138,16 +136,17 @@ func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Con
138136
clusterScope.Info("Creating floating IP", "ipVersion", ipVersion, "target", target)
139137
fip, err = clusterScope.CloudscaleClient.FloatingIPs.Create(ctx, req)
140138
if err != nil {
141-
return false, fmt.Errorf("creating floating IP: %w", err)
139+
return fmt.Errorf("creating floating IP: %w", err)
142140
}
143141

144-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = fip.HREF
145-
clusterScope.Info("Created floating IP", "ip", fip.Network, "id", fip.HREF)
142+
ip := fip.IP()
143+
clusterScope.CloudscaleCluster.Status.FloatingIP = ip
144+
clusterScope.Info("Created floating IP", "ip", fip.Network, "id", ip)
146145
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPCreated", "CreateFloatingIP",
147-
"Created floating IP %s", fip.IP())
146+
"Created floating IP %s", ip)
148147

149148
r.setControlPlaneEndpointFromFIP(clusterScope, fip)
150-
return false, nil
149+
return nil
151150
}
152151

153152
type floatingIPTarget struct {
@@ -214,12 +213,13 @@ func (r *CloudscaleClusterReconciler) ensureFloatingIPAssignment(ctx context.Con
214213
}
215214

216215
if needsUpdate {
217-
clusterScope.Info("Reassigning floating IP", "ip", fip.IP(), "target", target)
218-
if err := clusterScope.CloudscaleClient.FloatingIPs.Update(ctx, fip.HREF, updateReq); err != nil {
216+
floatingIP := clusterScope.CloudscaleCluster.Status.FloatingIP
217+
clusterScope.Info("Reassigning floating IP", "ip", floatingIP, "target", target)
218+
if err := clusterScope.CloudscaleClient.FloatingIPs.Update(ctx, floatingIP, updateReq); err != nil {
219219
return fmt.Errorf("updating floating IP assignment: %w", err)
220220
}
221221
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPReassigned", "UpdateFloatingIP",
222-
"Reassigned floating IP %s to %s", fip.IP(), target)
222+
"Reassigned floating IP %s to %s", floatingIP, target)
223223
}
224224

225225
return nil
@@ -230,13 +230,15 @@ func (r *CloudscaleClusterReconciler) setControlPlaneEndpointFromFIP(clusterScop
230230
return
231231
}
232232

233+
floatingIP := fip.IP()
234+
233235
apiServerPort := clusterScope.CloudscaleCluster.Spec.ControlPlaneLoadBalancer.APIServerPort
234-
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host = fip.IP()
236+
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host = floatingIP
235237
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Port = apiServerPort
236238
clusterScope.Info("Set control plane endpoint from floating IP",
237-
"endpoint", fip.IP(), "port", apiServerPort)
239+
"endpoint", floatingIP, "port", apiServerPort)
238240
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "ControlPlaneSet", "SetControlPlaneEndpoint",
239-
"Control plane endpoint set to %s:%d (floating IP)", fip.IP(), apiServerPort)
241+
"Control plane endpoint set to %s:%d (floating IP)", floatingIP, apiServerPort)
240242
}
241243

242244
// deleteFloatingIP deletes the floating IP if it's managed.
@@ -261,22 +263,22 @@ func (r *CloudscaleClusterReconciler) deleteFloatingIP(ctx context.Context, clus
261263
return nil
262264
}
263265

264-
fipID := clusterScope.CloudscaleCluster.Status.FloatingIPHREF
265-
if fipID == "" {
266+
floatingIP := clusterScope.CloudscaleCluster.Status.FloatingIP
267+
if floatingIP == "" {
266268
return nil
267269
}
268270

269-
clusterScope.Info("Deleting floating IP", "id", fipID)
270-
if err := clusterScope.CloudscaleClient.FloatingIPs.Delete(ctx, fipID); err != nil {
271+
clusterScope.Info("Deleting floating IP", "id", floatingIP)
272+
if err := clusterScope.CloudscaleClient.FloatingIPs.Delete(ctx, floatingIP); err != nil {
271273
if !cloudscale.IsNotFound(err) {
272274
return fmt.Errorf("deleting floating IP: %w", err)
273275
}
274-
clusterScope.Info("Floating IP already deleted", "id", fipID)
276+
clusterScope.Info("Floating IP already deleted", "id", floatingIP)
275277
}
276278

277279
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPDeleted", "DeleteFloatingIP",
278-
"Deleted floating IP %s", fipID)
279-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = ""
280+
"Deleted floating IP %s", floatingIP)
281+
clusterScope.CloudscaleCluster.Status.FloatingIP = ""
280282

281283
return nil
282284
}

internal/controller/cloudscalecluster_network.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ func (r *CloudscaleClusterReconciler) setNetworkStatus(clusterScope *scope.Clust
225225

226226
// networkTags returns the tags for a specific named network, combining cluster ownership with network name.
227227
func (r *CloudscaleClusterReconciler) networkTags(clusterScope *scope.ClusterScope, networkName string) cloudscalesdk.TagMap {
228-
tags := clusterOwnershipTags(clusterScope.CloudscaleCluster)
229-
tags[infrastructurev1beta2.NameCloudscaleProviderPrefix+"network-name"] = networkName
228+
tags := cloudscalesdk.TagMap{
229+
infrastructurev1beta2.NameCloudscaleProviderOwned + clusterScope.Cluster.Name: networkName,
230+
}
230231
return tags
231232
}

test/e2e/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func validateCloudscaleResources(proxy framework.ClusterProxy, namespace, cluste
6060

6161
// Validate floating IP (if configured)
6262
if cloudscaleCluster.Spec.FloatingIP != nil {
63-
Expect(cloudscaleCluster.Status.FloatingIPHREF).NotTo(BeEmpty(), "FloatingIPHREF should be set when floating IP is configured")
63+
Expect(cloudscaleCluster.Status.FloatingIP).NotTo(BeEmpty(), "FloatingIP should be set when floating IP is configured")
6464
}
6565

6666
// Validate provisioned status

0 commit comments

Comments
 (0)