Skip to content

Commit

Permalink
Merge pull request #456 from mogren/avoid-unecessary-call
Browse files Browse the repository at this point in the history
Avoid unnecessary call to EC2
  • Loading branch information
Claes Mogren authored May 9, 2019
2 parents 3460788 + d7c7950 commit 0c54452
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,11 @@ func (cache *EC2InstanceMetadataCache) AllocIPAddresses(eniID string, numIPs int
needIPs = ipLimit
}

// If we don't need any more IPs, exit
if needIPs < 1 {
return nil
}

log.Infof("Trying to allocate %d IP address on ENI %s", needIPs, eniID)

input := &ec2.AssignPrivateIpAddressesInput{
Expand Down
5 changes: 5 additions & 0 deletions pkg/awsutils/awsutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ func TestAllocIPAddresses(t *testing.T) {
err = ins.AllocIPAddresses("eni-id", 30)

assert.NoError(t, err)

// Adding 0 should do nothing
err = ins.AllocIPAddresses("eni-id", 0)

assert.NoError(t, err)
}

func TestAllocAllIPAddressOnErr(t *testing.T) {
Expand Down

0 comments on commit 0c54452

Please sign in to comment.