@@ -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
6768func (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
8586func (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}
0 commit comments