Skip to content

Commit

Permalink
Change tryAssignIPs to assign up to configured WARM_IP_TARGET (#1279) (
Browse files Browse the repository at this point in the history
…#1495)

Previously tryAssignIPs would always allocate all available IPs on the
ENI regardless of the number of IPs the node would want. A great
showcase of this behavior is on node bootstrap. Assuming we have a node
with maxIPsPerENI=30 and WARM_IP_TARGET=5, the following happens:
- Node starts with single IP
- tryAssignIPs allocates an additional 29 IPs
- decreaseIPPool will release 29-5=24 IPs

After the change this would look like:
- Node starts with a single IP
- tryAssignIPs allocates an additional 5 IPs

So in this very common flow we cut out an entire AWS API call per node.
In addition this behavior exhibits itself any time we need to scale up
IPs as tryAssignIPs always attempts to over-allocate IPs -- which then
just need to be released almost immediately.

Fixes #1272

Co-authored-by: Thomas Jackson <jacksontj.89@gmail.com>
  • Loading branch information
M00nF1sh and jacksontj authored Jun 7, 2021
1 parent 45bcab5 commit c605851
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ipamd
import (
"context"
"fmt"
"math"
"net"
"os"
"strconv"
Expand Down Expand Up @@ -746,12 +747,19 @@ func (c *IPAMContext) tryAssignIPs() (increasedPool bool, err error) {
return false, nil
}

// If WARM_IP_TARGET is set we only want to allocate up to that target
// to avoid overallocating and releasing
toAllocate := c.maxIPsPerENI
if warmIPTargetDefined {
toAllocate = short
}

// Find an ENI where we can add more IPs
eni := c.dataStore.GetENINeedsIP(c.maxIPsPerENI, c.useCustomNetworking)
if eni != nil && len(eni.IPv4Addresses) < c.maxIPsPerENI {
currentNumberOfAllocatedIPs := len(eni.IPv4Addresses)
// Try to allocate all available IPs for this ENI
err = c.awsClient.AllocIPAddresses(eni.ID, c.maxIPsPerENI-currentNumberOfAllocatedIPs)
err = c.awsClient.AllocIPAddresses(eni.ID, int(math.Min(float64(c.maxIPsPerENI-currentNumberOfAllocatedIPs), float64(toAllocate))))
if err != nil {
log.Warnf("failed to allocate all available IP addresses on ENI %s, err: %v", eni.ID, err)
// Try to just get one more IP
Expand Down

0 comments on commit c605851

Please sign in to comment.