Skip to content

Commit

Permalink
Merge pull request #1870 from elastx/ip_pool_duplicate_addresses
Browse files Browse the repository at this point in the history
OpenstackFloatingIPPool: Adds popped ip to claimedIPs #1869
  • Loading branch information
k8s-ci-robot authored Feb 9, 2024
2 parents 7622602 + cca2213 commit ca15733
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions controllers/openstackfloatingippool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileIPAddresses(ctx context.Con
return err
}
}
unclaimedPreAllocatedIPs := diff(pool.Spec.PreAllocatedFloatingIPs, pool.Status.ClaimedIPs)
unclaimedIPs := union(pool.Status.AvailableIPs, unclaimedPreAllocatedIPs)
allIPs := union(pool.Status.AvailableIPs, pool.Spec.PreAllocatedFloatingIPs)
unclaimedIPs := diff(allIPs, pool.Status.ClaimedIPs)
pool.Status.AvailableIPs = diff(unclaimedIPs, pool.Status.FailedIPs)
return nil
}
Expand All @@ -313,7 +313,7 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
}

// Get tagged floating IPs and add them to the available IPs if they are not present in either the available IPs or the claimed IPs
// This is done to prevent leaking floating IPs if to prevent leaking floating IPs if the floating IP was created but the IPAddress object was not
// This is done to prevent leaking floating IPs if the floating IP was created but the IPAddress object was not
if len(pool.Status.AvailableIPs) == 0 {
taggedIPs, err := networkingService.GetFloatingIPsByTag(pool.GetFloatingIPTag())
if err != nil {
Expand All @@ -332,6 +332,7 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
if len(pool.Status.AvailableIPs) > 0 {
ip = pool.Status.AvailableIPs[0]
pool.Status.AvailableIPs = pool.Status.AvailableIPs[1:]
pool.Status.ClaimedIPs = append(pool.Status.ClaimedIPs, ip)
}

if ip != "" {
Expand All @@ -342,15 +343,13 @@ func (r *OpenStackFloatingIPPoolReconciler) getIP(ctx context.Context, scope sco
if fp != nil {
return fp.FloatingIP, nil
}
pool.Status.FailedIPs = append(pool.Status.FailedIPs, ip)
}

fp, err := networkingService.CreateFloatingIPForPool(pool)
if err != nil {
scope.Logger().Error(err, "Failed to create floating IP", "pool", pool.Name)
conditions.MarkFalse(pool, infrav1alpha1.OpenstackFloatingIPPoolReadyCondition, infrav1.OpenStackErrorReason, clusterv1.ConditionSeverityError, "Failed to create floating IP: %v", err)
if ip != "" {
pool.Status.FailedIPs = append(pool.Status.FailedIPs, ip)
}
return "", err
}
defer func() {
Expand Down

0 comments on commit ca15733

Please sign in to comment.