From 7f532635518bf631c4df1c61948c90070f216be2 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Mon, 5 Oct 2015 00:40:17 -0700 Subject: [PATCH] ipam must honor preferedIP ahead of random allocation from subPool Currently the default ipam implementation ignores the prefered ip if the request is made on an existing sub-pool. The priority should be other way around. Signed-off-by: Madhu Venugopal --- ipam/allocator.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index 90dfb4a..5104d38 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -425,16 +425,16 @@ func (a *Allocator) getAddress(nw *net.IPNet, bitmask *bitseq.Handle, prefAddres } if ipr == nil && prefAddress == nil { ordinal, err = bitmask.SetAny() - } else if ipr != nil { - base.IP = ipr.Sub.IP - ordinal, err = bitmask.SetAnyInRange(ipr.Start, ipr.End) - } else { + } else if prefAddress != nil { hostPart, e := types.GetHostPartIP(prefAddress, base.Mask) if e != nil { return nil, fmt.Errorf("failed to allocate preferred address %s: %v", prefAddress.String(), e) } ordinal = ipToUint32(types.GetMinimalIP(hostPart)) err = bitmask.Set(ordinal) + } else { + base.IP = ipr.Sub.IP + ordinal, err = bitmask.SetAnyInRange(ipr.Start, ipr.End) } if err != nil { return nil, ipamapi.ErrNoAvailableIPs