in pkg/ipamd/ipamd.go [871:923]
func (c *IPAMContext) tryAllocateENI(ctx context.Context) error {
var securityGroups []*string
var eniCfgSubnet string
if c.useCustomNetworking {
eniCfg, err := eniconfig.MyENIConfig(ctx, c.k8sClient)
if err != nil {
log.Errorf("Failed to get pod ENI config")
return err
}
log.Infof("ipamd: using custom network config: %v, %s", eniCfg.SecurityGroups, eniCfg.Subnet)
for _, sgID := range eniCfg.SecurityGroups {
log.Debugf("Found security-group id: %s", sgID)
securityGroups = append(securityGroups, aws.String(sgID))
}
eniCfgSubnet = eniCfg.Subnet
}
resourcesToAllocate := c.GetENIResourcesToAllocate()
if resourcesToAllocate > 0 {
eni, err := c.awsClient.AllocENI(c.useCustomNetworking, securityGroups, eniCfgSubnet, resourcesToAllocate)
if err != nil {
log.Errorf("Failed to increase pool size due to not able to allocate ENI %v", err)
ipamdErrInc("increaseIPPoolAllocENI")
log.Warnf("Failed to allocate %d IP addresses on an ENI: %v", resourcesToAllocate, err)
if containsInsufficientCIDRsOrSubnetIPs(err) {
ipamdErrInc("increaseIPPoolAllocIPAddressesFailed")
log.Errorf("Unable to attach IPs/Prefixes for the ENI, subnet doesn't seem to have enough IPs/Prefixes. Consider using new subnet or carve a reserved range using create-subnet-cidr-reservation")
c.lastInsufficientCidrError = time.Now()
}
return err
}
eniMetadata, err := c.awsClient.WaitForENIAndIPsAttached(eni, resourcesToAllocate)
if err != nil {
ipamdErrInc("increaseIPPoolwaitENIAttachedFailed")
log.Errorf("Failed to increase pool size: Unable to discover attached ENI from metadata service %v", err)
return err
}
// The CNI does not create trunk or EFA ENIs, so they will always be false here
err = c.setupENI(eni, eniMetadata, false, false)
if err != nil {
ipamdErrInc("increaseIPPoolsetupENIFailed")
log.Errorf("Failed to increase pool size: %v", err)
return err
}
} else {
log.Debugf("Did not allocate ENI since IPs/Prefixes needed were not greater than 0. IPs/Prefixes needed: %d", resourcesToAllocate)
}
return nil
}