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