Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPs to the first ENI on startup #648

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 err == nil && increasedPool {
c.updateLastNodeIPPoolAction()
}
return err
}

func (c *IPAMContext) getLocalPodsWithRetry() ([]*k8sapi.K8SPodInfo, error) {
Expand Down Expand Up @@ -661,9 +666,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)
mogren marked this conversation as resolved.
Show resolved Hide resolved
// Try to allocate all available IPs for this ENI
// TODO: Retry with back-off, trying with half the number of IPs each time
mogren marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -148,6 +148,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(gomock.Any(), gomock.Any())
mockAWS.EXPECT().DescribeENI(gomock.Any()).Return(eniResp, &attachmentID, nil)

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