@@ -244,7 +244,18 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
244
244
return err
245
245
}
246
246
247
+ var statusFloatingIP * string
248
+ var specFloatingIP * string
247
249
if openStackCluster .Status .Bastion != nil && openStackCluster .Status .Bastion .FloatingIP != "" {
250
+ // Floating IP set in status
251
+ statusFloatingIP = & openStackCluster .Status .Bastion .FloatingIP
252
+ }
253
+ if openStackCluster .Spec .Bastion .FloatingIP != nil {
254
+ // Floating IP from the spec
255
+ specFloatingIP = openStackCluster .Spec .Bastion .FloatingIP
256
+ }
257
+
258
+ if statusFloatingIP != nil && (specFloatingIP == nil || * statusFloatingIP != * specFloatingIP ) {
248
259
if err = networkingService .DeleteFloatingIP (openStackCluster , openStackCluster .Status .Bastion .FloatingIP ); err != nil {
249
260
handleUpdateOSCError (openStackCluster , fmt .Errorf ("failed to delete floating IP: %w" , err ), false )
250
261
return fmt .Errorf ("failed to delete floating IP: %w" , err )
@@ -270,6 +281,10 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
270
281
271
282
for _ , address := range addresses {
272
283
if address .Type == corev1 .NodeExternalIP {
284
+ // If a floating IP is set for the bastion spec, skip deleting it
285
+ if specFloatingIP != nil && address .Address == * specFloatingIP {
286
+ continue
287
+ }
273
288
// Floating IP may not have properly saved in bastion status (thus not deleted above), delete any remaining floating IP
274
289
if err = networkingService .DeleteFloatingIP (openStackCluster , address .Address ); err != nil {
275
290
handleUpdateOSCError (openStackCluster , fmt .Errorf ("failed to delete floating IP: %w" , err ), false )
0 commit comments