Skip to content

Commit a54517c

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

6 files changed

Lines changed: 39 additions & 36 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

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: 30 additions & 23 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"
@@ -67,7 +68,7 @@ func (r *CloudscaleClusterReconciler) reconcileFloatingIP(ctx context.Context, c
6768
func (r *CloudscaleClusterReconciler) reconcileBYOFloatingIP(ctx context.Context, clusterScope *scope.ClusterScope, uuid string) error {
6869
// Cached: status + endpoint already populated from a prior reconcile.
6970
// BYO FIPs are immutable from CAPCS' perspective, so no need to refetch.
70-
if clusterScope.CloudscaleCluster.Status.FloatingIPHREF != "" &&
71+
if clusterScope.CloudscaleCluster.Status.FloatingIP != "" &&
7172
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host != "" {
7273
return nil
7374
}
@@ -77,26 +78,29 @@ func (r *CloudscaleClusterReconciler) reconcileBYOFloatingIP(ctx context.Context
7778
return fmt.Errorf("getting BYO floating IP %s: %w", uuid, err)
7879
}
7980

80-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = fip.HREF
81+
clusterScope.CloudscaleCluster.Status.FloatingIP = fip.IP()
8182
r.setControlPlaneEndpointFromFIP(clusterScope, fip)
8283
return nil
8384
}
8485

8586
func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Context, clusterScope *scope.ClusterScope, fipSpec *infrastructurev1beta2.FloatingIPSpec) (pending bool, _ error) {
87+
logger := logf.FromContext(ctx)
8688
tags := clusterOwnershipTags(clusterScope.CloudscaleCluster)
8789

90+
logger.Info("reconcile managed floating IP")
91+
8892
// Check if the floating IP already exists (by status ID or by tags)
8993
fip, id, err := ensureResource(ctx, clusterScope,
90-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF,
94+
clusterScope.CloudscaleCluster.Status.FloatingIP,
9195
"floating IP",
9296
clusterScope.CloudscaleClient.FloatingIPs,
93-
func(fip cloudscalesdk.FloatingIP) string { return fip.HREF },
97+
func(fip cloudscalesdk.FloatingIP) string { return fip.IP() },
9498
tags,
9599
)
96100
if err != nil {
97101
return false, err
98102
}
99-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = id
103+
clusterScope.CloudscaleCluster.Status.FloatingIP = id
100104

101105
if id != "" {
102106
// Existing floating IP: ensure it's assigned to the right target and set endpoint
@@ -126,8 +130,7 @@ func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Con
126130
// Assign to LB or CP server
127131
target, err := r.getFloatingIPTarget(ctx, clusterScope)
128132
if err != nil {
129-
// No target available yet (LB or CP server not ready)
130-
return true, nil
133+
logger.Info("no target available yet", "err", err)
131134
}
132135
if target.lbUUID != "" {
133136
req.LoadBalancer = target.lbUUID
@@ -141,10 +144,11 @@ func (r *CloudscaleClusterReconciler) reconcileManagedFloatingIP(ctx context.Con
141144
return false, fmt.Errorf("creating floating IP: %w", err)
142145
}
143146

144-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = fip.HREF
145-
clusterScope.Info("Created floating IP", "ip", fip.Network, "id", fip.HREF)
147+
floatingIP := fip.IP()
148+
clusterScope.CloudscaleCluster.Status.FloatingIP = floatingIP
149+
clusterScope.Info("Created floating IP", "ip", fip.Network, "id", floatingIP)
146150
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPCreated", "CreateFloatingIP",
147-
"Created floating IP %s", fip.IP())
151+
"Created floating IP %s", floatingIP)
148152

149153
r.setControlPlaneEndpointFromFIP(clusterScope, fip)
150154
return false, nil
@@ -214,12 +218,13 @@ func (r *CloudscaleClusterReconciler) ensureFloatingIPAssignment(ctx context.Con
214218
}
215219

216220
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 {
221+
floatingIP := clusterScope.CloudscaleCluster.Status.FloatingIP
222+
clusterScope.Info("Reassigning floating IP", "ip", floatingIP, "target", target)
223+
if err := clusterScope.CloudscaleClient.FloatingIPs.Update(ctx, floatingIP, updateReq); err != nil {
219224
return fmt.Errorf("updating floating IP assignment: %w", err)
220225
}
221226
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPReassigned", "UpdateFloatingIP",
222-
"Reassigned floating IP %s to %s", fip.IP(), target)
227+
"Reassigned floating IP %s to %s", floatingIP, target)
223228
}
224229

225230
return nil
@@ -230,13 +235,15 @@ func (r *CloudscaleClusterReconciler) setControlPlaneEndpointFromFIP(clusterScop
230235
return
231236
}
232237

238+
floatingIP := fip.IP()
239+
233240
apiServerPort := clusterScope.CloudscaleCluster.Spec.ControlPlaneLoadBalancer.APIServerPort
234-
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host = fip.IP()
241+
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Host = floatingIP
235242
clusterScope.CloudscaleCluster.Spec.ControlPlaneEndpoint.Port = apiServerPort
236243
clusterScope.Info("Set control plane endpoint from floating IP",
237-
"endpoint", fip.IP(), "port", apiServerPort)
244+
"endpoint", floatingIP, "port", apiServerPort)
238245
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "ControlPlaneSet", "SetControlPlaneEndpoint",
239-
"Control plane endpoint set to %s:%d (floating IP)", fip.IP(), apiServerPort)
246+
"Control plane endpoint set to %s:%d (floating IP)", floatingIP, apiServerPort)
240247
}
241248

242249
// deleteFloatingIP deletes the floating IP if it's managed.
@@ -261,22 +268,22 @@ func (r *CloudscaleClusterReconciler) deleteFloatingIP(ctx context.Context, clus
261268
return nil
262269
}
263270

264-
fipID := clusterScope.CloudscaleCluster.Status.FloatingIPHREF
265-
if fipID == "" {
271+
floatingIP := clusterScope.CloudscaleCluster.Status.FloatingIP
272+
if floatingIP == "" {
266273
return nil
267274
}
268275

269-
clusterScope.Info("Deleting floating IP", "id", fipID)
270-
if err := clusterScope.CloudscaleClient.FloatingIPs.Delete(ctx, fipID); err != nil {
276+
clusterScope.Info("Deleting floating IP", "id", floatingIP)
277+
if err := clusterScope.CloudscaleClient.FloatingIPs.Delete(ctx, floatingIP); err != nil {
271278
if !cloudscale.IsNotFound(err) {
272279
return fmt.Errorf("deleting floating IP: %w", err)
273280
}
274-
clusterScope.Info("Floating IP already deleted", "id", fipID)
281+
clusterScope.Info("Floating IP already deleted", "id", floatingIP)
275282
}
276283

277284
r.recorder.Eventf(clusterScope.CloudscaleCluster, nil, corev1.EventTypeNormal, "FloatingIPDeleted", "DeleteFloatingIP",
278-
"Deleted floating IP %s", fipID)
279-
clusterScope.CloudscaleCluster.Status.FloatingIPHREF = ""
285+
"Deleted floating IP %s", floatingIP)
286+
clusterScope.CloudscaleCluster.Status.FloatingIP = ""
280287

281288
return nil
282289
}

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)