Skip to content

Commit

Permalink
Add IPs to the first ENI on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Claes Mogren committed Oct 8, 2019
1 parent 04a795f commit f87f732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ func (c *IPAMContext) nodeInit() error {
log.Errorf("UpdateRuleListBySrc in nodeInit() failed for IP %s: %v", ip.IP, err)
}
}
return nil
// For a new node, attach IPs
increasedPool, err := c.tryAssignIPs()
if increasedPool {
c.updateLastNodeIPPoolAction()
}
return err
}

func (c *IPAMContext) getLocalPodsWithRetry() ([]*k8sapi.K8SPodInfo, error) {
Expand Down Expand Up @@ -651,9 +656,7 @@ func (c *IPAMContext) tryAssignIPs() (increasedPool bool, err error) {
eni := c.dataStore.GetENINeedsIP(c.maxIPsPerENI, c.useCustomNetworking)
if eni != nil && len(eni.IPv4Addresses) < c.maxIPsPerENI {
currentNumberOfAllocatedIPs := len(eni.IPv4Addresses)
log.Debugf("Found ENI %s that has less than the maximum number of IP addresses allocated: cur=%d, max=%d", eni.ID, currentNumberOfAllocatedIPs, c.maxIPsPerENI)
// Try to allocate all available IPs for this ENI
// TODO: Retry with back-off, trying with half the number of IPs each time
err = c.awsClient.AllocIPAddresses(eni.ID, c.maxIPsPerENI-currentNumberOfAllocatedIPs)
if err != nil {
log.Warnf("failed to allocate all available IP addresses on ENI %s, err: %v", eni.ID, err)
Expand Down
3 changes: 3 additions & 0 deletions ipamd/ipamd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func TestNodeInit(t *testing.T) {
mockAWS.EXPECT().GetVPCIPv4CIDRs().Return(cidrs)
mockNetwork.EXPECT().UseExternalSNAT().Return(false)
mockNetwork.EXPECT().UpdateRuleListBySrc(gomock.Any(), gomock.Any(), gomock.Any(), true)
// Add IPs
mockAWS.EXPECT().AllocIPAddresses(primaryENIid, gomock.Any())
mockAWS.EXPECT().DescribeENI(primaryENIid).Return(eniResp, &attachmentID, nil)

err := mockContext.nodeInit()
assert.NoError(t, err)
Expand Down

0 comments on commit f87f732

Please sign in to comment.