Skip to content

Commit

Permalink
Do not allocate a second IP on freshly minted interfaces (#17)
Browse files Browse the repository at this point in the history
Previously, we would create a second IP immediately instead of just
using the previous IP address. This patch will use the initial IP
address from a newly made interface if it is the only IP known to the
system.
  • Loading branch information
theatrus authored Jan 3, 2018
1 parent dbdced3 commit 945f303
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plugin/ipam/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ func cmdAdd(args *skel.CmdArgs) error {
if err != nil {
// failed, so attempt to add an IP to a new interface
newIf, err := aws.NewInterface(conf.IPAM.SecGroupIds, conf.IPAM.SubnetTags)
if err != nil {
// If this interface has somehow gained more than one IP since being allocated,
// abort this process and let a subsequent run find a valid IP.
if err != nil || len(newIf.IPv4s) != 1 {
return fmt.Errorf("unable to create a new elastic network interface due to %v",
err)
}
alloc, err = aws.AllocateIPOn(*newIf)
if err != nil {
return fmt.Errorf("unable to allocate an IP due to %v",
err)
// Freshly allocated interfaces will always have one valid IP - use
// this IP address.
alloc = &aws.AllocationResult{
&newIf.IPv4s[0],
*newIf,
}
}
}
Expand Down

0 comments on commit 945f303

Please sign in to comment.