From e8fcd21baa563521668f7dd66182a554f72bfb05 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 25 Oct 2019 17:13:09 +0000 Subject: [PATCH 1/2] Retry IP allocator claims It may be that we cannot talk to a peer straight away, so allow claims to be retried a few times before giving up. --- ipam/claim.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ipam/claim.go b/ipam/claim.go index c4a5529e..02ba251e 100644 --- a/ipam/claim.go +++ b/ipam/claim.go @@ -12,6 +12,7 @@ import ( type claim struct { resultChan chan<- error + tryCount int ident string // a container ID, something like "weave:expose", or api.NoContainerID cidr address.CIDR // single address being claimed isContainer bool // true if ident is a container ID @@ -19,6 +20,8 @@ type claim struct { hasBeenCancelled func() bool } +const maxTryCount = 5 + // Send an error (or nil for success) back to caller listening on resultChan func (c *claim) sendResult(result error) { // Make sure we only send a result once, since listener stops listening after that @@ -40,6 +43,8 @@ func (c *claim) Try(alloc *Allocator) bool { return true } + c.tryCount++ + addOwned := func() { if c.ident == api.NoContainerID { alloc.addOwned(c.cidr.Addr.String(), c.cidr, c.isContainer) @@ -90,8 +95,10 @@ func (c *claim) Try(alloc *Allocator) bool { if c.noErrorOnUnknown { alloc.infof("Claim %s for %s: %s; will try later.", c.cidr, c.ident, err) c.sendResult(nil) - } else { // just tell the user they can't do this. - c.deniedBy(alloc, owner) + } else if c.tryCount > maxTryCount { + // give up, tell the user they can't do this + c.deniedBy(alloc, owner, err) + return true } } return false From a43bd88ddd107eaa14ee1f5759e784325108283b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 25 Oct 2019 17:13:59 +0000 Subject: [PATCH 2/2] Add the error message why an IP claim is denied --- ipam/allocator.go | 2 +- ipam/claim.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index 831b9862..6dbd7f37 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -275,7 +275,7 @@ func (alloc *Allocator) spaceRequestDenied(sender mesh.PeerName, r address.Range for i := 0; i < len(alloc.pendingClaims); { claim := alloc.pendingClaims[i].(*claim) if r.Contains(claim.cidr.Addr) { - claim.deniedBy(alloc, sender) + claim.deniedBy(alloc, sender, nil) alloc.pendingClaims = append(alloc.pendingClaims[:i], alloc.pendingClaims[i+1:]...) continue } diff --git a/ipam/claim.go b/ipam/claim.go index 02ba251e..153eb7d1 100644 --- a/ipam/claim.go +++ b/ipam/claim.go @@ -135,12 +135,16 @@ func (c *claim) Try(alloc *Allocator) bool { return true } -func (c *claim) deniedBy(alloc *Allocator, owner mesh.PeerName) { +func (c *claim) deniedBy(alloc *Allocator, owner mesh.PeerName, err error) { name, found := alloc.nicknames[owner] if found { name = " (" + name + ")" } - c.sendResult(fmt.Errorf("address %s is owned by other peer %s%s", c.cidr.String(), owner, name)) + reason := "" + if err != nil { + reason = fmt.Sprintf(" - %s", err) + } + c.sendResult(fmt.Errorf("address %s is owned by other peer %s%s%s", c.cidr.String(), owner, name, reason)) } func (c *claim) Cancel() {