Skip to content

Commit f712e66

Browse files
Do not delete bastion floating ip if set in spec
1 parent 7b41e34 commit f712e66

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

controllers/openstackcluster_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,18 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
249249
return err
250250
}
251251

252+
var statusFloatingIP *string
253+
var specFloatingIP *string
252254
if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.FloatingIP != "" {
255+
// Floating IP set in status
256+
statusFloatingIP = &openStackCluster.Status.Bastion.FloatingIP
257+
}
258+
if openStackCluster.Spec.Bastion.FloatingIP != nil {
259+
// Floating IP from the spec
260+
specFloatingIP = openStackCluster.Spec.Bastion.FloatingIP
261+
}
262+
263+
if statusFloatingIP != nil && (specFloatingIP == nil || *statusFloatingIP != *specFloatingIP) {
253264
if err = networkingService.DeleteFloatingIP(openStackCluster, openStackCluster.Status.Bastion.FloatingIP); err != nil {
254265
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)
255266
return fmt.Errorf("failed to delete floating IP: %w", err)
@@ -275,6 +286,10 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
275286

276287
for _, address := range addresses {
277288
if address.Type == corev1.NodeExternalIP {
289+
// If a floating IP is set for the bastion spec, skip deleting it
290+
if specFloatingIP != nil && address.Address == *specFloatingIP {
291+
continue
292+
}
278293
// Floating IP may not have properly saved in bastion status (thus not deleted above), delete any remaining floating IP
279294
if err = networkingService.DeleteFloatingIP(openStackCluster, address.Address); err != nil {
280295
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)

0 commit comments

Comments
 (0)