From 2652c36d1891562e8a7fd02e77b86e64565da368 Mon Sep 17 00:00:00 2001 From: Claes Mogren Date: Tue, 8 Oct 2019 15:05:16 -0700 Subject: [PATCH] Add IPs to the first ENI on startup --- ipamd/ipamd.go | 9 ++++++--- ipamd/ipamd_test.go | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ipamd/ipamd.go b/ipamd/ipamd.go index b39762f72e..e1b3eed5dc 100644 --- a/ipamd/ipamd.go +++ b/ipamd/ipamd.go @@ -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) { @@ -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) // 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) diff --git a/ipamd/ipamd_test.go b/ipamd/ipamd_test.go index 7cd487a49d..fbae617d1b 100644 --- a/ipamd/ipamd_test.go +++ b/ipamd/ipamd_test.go @@ -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)