Skip to content

Commit 1744ff4

Browse files
authored
Merge pull request #2484 from k8s-infra-cherrypick-robot/cherry-pick-2257-to-release-0.12
[release-0.12] Do not delete bastion floating ip if set in spec
2 parents 767d0f6 + a12c44c commit 1744ff4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

controllers/openstackcluster_controller.go

+16
Original file line numberDiff line numberDiff line change
@@ -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+
statusFloatingIP = &openStackCluster.Status.Bastion.FloatingIP
255+
}
256+
if openStackCluster.Spec.Bastion != nil && openStackCluster.Spec.Bastion.FloatingIP != nil {
257+
specFloatingIP = openStackCluster.Spec.Bastion.FloatingIP
258+
}
259+
260+
// We only remove the bastion's floating IP if it exists and if it's not the same value defined both in the spec and in status.
261+
// This decision was made so if a user specifies a pre-created floating IP that is intended to only be used for the bastion, the floating IP won't get removed once the bastion is destroyed.
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,11 @@ 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 retrieved is the same as what is set in the bastion spec, skip deleting it.
289+
// This decision was made so if a user specifies a pre-created floating IP that is intended to only be used for the bastion, the floating IP won't get removed once the bastion is destroyed.
290+
if specFloatingIP != nil && address.Address == *specFloatingIP {
291+
continue
292+
}
277293
// Floating IP may not have properly saved in bastion status (thus not deleted above), delete any remaining floating IP
278294
if err = networkingService.DeleteFloatingIP(openStackCluster, address.Address); err != nil {
279295
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err), false)

0 commit comments

Comments
 (0)