@@ -248,7 +248,18 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
248248 return err
249249 }
250250
251+ var statusFloatingIP * string
252+ var specFloatingIP * string
251253 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 ) {
252263 if err = networkingService .DeleteFloatingIP (openStackCluster , openStackCluster .Status .Bastion .FloatingIP ); err != nil {
253264 handleUpdateOSCError (openStackCluster , fmt .Errorf ("failed to delete floating IP: %w" , err ), false )
254265 return fmt .Errorf ("failed to delete floating IP: %w" , err )
@@ -274,6 +285,10 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
274285
275286 for _ , address := range addresses {
276287 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+ }
277292 // Floating IP may not have properly saved in bastion status (thus not deleted above), delete any remaining floating IP
278293 if err = networkingService .DeleteFloatingIP (openStackCluster , address .Address ); err != nil {
279294 handleUpdateOSCError (openStackCluster , fmt .Errorf ("failed to delete floating IP: %w" , err ), false )
0 commit comments