Skip to content

Commit c1fe7b8

Browse files
Do not delete bastion floating ip if set in spec
1 parent 90da86d commit c1fe7b8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

controllers/openstackcluster_controller.go

+15
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,18 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
244244
return err
245245
}
246246

247+
var statusFloatingIP *string
248+
var specFloatingIP *string
247249
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) {
248259
if err = networkingService.DeleteFloatingIP(openStackCluster, openStackCluster.Status.Bastion.FloatingIP); err != nil {
249260
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)
250261
return fmt.Errorf("failed to delete floating IP: %w", err)
@@ -270,6 +281,10 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
270281

271282
for _, address := range addresses {
272283
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+
}
273288
// Floating IP may not have properly saved in bastion status (thus not deleted above), delete any remaining floating IP
274289
if err = networkingService.DeleteFloatingIP(openStackCluster, address.Address); err != nil {
275290
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)

0 commit comments

Comments
 (0)