Return all applicable results from Lookup

and stop erroring on Lookup not found; just return a blank result
This commit is contained in:
Bryan Boreham committed 2016-03-02 17:01:12 -08:00
1 parent 03563e847e
commit b6eec08247
5 files changed
+31 -22

No files matched your search

+9 -13
View File
@@ -203,18 +203,13 @@ func (alloc *Allocator) Allocate(ident string, r address.Range, hasBeenCancelled
return result.addr, result.err
}
// Lookup (Sync) - get existing IP address for container with given name in range
func (alloc *Allocator) Lookup(ident string, r address.Range) (address.Address, error) {
resultChan := make(chan allocateResult)
// Lookup (Sync) - get existing IP addresses for container with given name in range
func (alloc *Allocator) Lookup(ident string, r address.Range) ([]address.Address, error) {
resultChan := make(chan []address.Address)
alloc.actionChan <- func() {
if addr, found := alloc.ownedInRange(ident, r); found {
resultChan <- allocateResult{addr: addr}
return
}
resultChan <- allocateResult{err: fmt.Errorf("lookup: no address found for %s in range %s", ident, r)}
resultChan <- alloc.ownedInRange(ident, r)
}
result := <-resultChan
return result.addr, result.err
return <-resultChan, nil
}
// Claim an address that we think we should own (Sync)
@@ -861,13 +856,14 @@ func (alloc *Allocator) removeOwned(ident string, addrToFree address.Address) bo
return false
}
func (alloc *Allocator) ownedInRange(ident string, r address.Range) (address.Address, bool) {
func (alloc *Allocator) ownedInRange(ident string, r address.Range) []address.Address {
var a []address.Address
for _, addr := range alloc.owned[ident] {
if r.Contains(addr) {
return addr, true
a = append(a, addr)
}
}
return 0, false
return a
}
func (alloc *Allocator) findOwner(addr address.Address) string {