Skip to content

Commit

Permalink
Remove IsFull check in IpPool.Allocate (submariner-io#251)
Browse files Browse the repository at this point in the history
This function is coded to return the existing allocated IP, if any, however the
IsFull check elides that if there's no available IPs. I assume this isn't
the intent so remove the up-front check as this case is handled anyway by the
subsequent code.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
  • Loading branch information
tpantelis committed Jan 30, 2020
1 parent 30c7418 commit 16f5483
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions pkg/globalnet/controllers/ipam/ippool.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ func intToIP(ip int) net.IP {
}

func (p *IpPool) Allocate(key string) (string, error) {
if p.IsFull() {
return "", errors.New("IPAM: No IP available for allocation")
}
p.Lock()
defer p.Unlock()
allocatedIp := p.allocated[key]
Expand All @@ -69,7 +66,7 @@ func (p *IpPool) Allocate(key string) (string, error) {
delete(p.available, k)
return k, nil
}
return "", errors.New("IPAM: Unable to allocate IP")
return "", errors.New("IPAM: No IP available for allocation")
}
return allocatedIp, nil
}
Expand Down Expand Up @@ -99,14 +96,6 @@ func (p *IpPool) GetAllocatedIp(key string) string {
return ip
}

func (p *IpPool) IsFull() bool {
var result bool
p.RLock()
result = len(p.available) == 0
p.RUnlock()
return result
}

func (p *IpPool) RequestIp(key string, ip string) (string, error) {
if p.GetAllocatedIp(key) == ip {
return ip, nil
Expand Down

0 comments on commit 16f5483

Please sign in to comment.