Skip to content

Commit

Permalink
Do not delete bastion floating ip if set in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-elastisys committed Aug 19, 2024
1 parent 90da86d commit c1fe7b8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,18 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s
return err
}

var statusFloatingIP *string
var specFloatingIP *string
if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.FloatingIP != "" {
// Floating IP set in status
statusFloatingIP = &openStackCluster.Status.Bastion.FloatingIP
}
if openStackCluster.Spec.Bastion.FloatingIP != nil {
// Floating IP from the spec
specFloatingIP = openStackCluster.Spec.Bastion.FloatingIP
}

if statusFloatingIP != nil && (specFloatingIP == nil || *statusFloatingIP != *specFloatingIP) {
if err = networkingService.DeleteFloatingIP(openStackCluster, openStackCluster.Status.Bastion.FloatingIP); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)
return fmt.Errorf("failed to delete floating IP: %w", err)
Expand All @@ -270,6 +281,10 @@ func (r *OpenStackClusterReconciler) deleteBastion(ctx context.Context, scope *s

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

0 comments on commit c1fe7b8

Please sign in to comment.