From f0915221d13f2181f58e7b0bb7af11b6a308bc09 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 23 Jul 2015 20:16:30 +0100 Subject: [PATCH] Rename 'reclaim' to 'noErrorUnknown' which describes the behaviour better --- ipam/allocator.go | 4 ++-- ipam/claim.go | 17 ++++++++--------- ipam/http.go | 4 ++-- weave | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index 0c8e22dd..36e1a1d8 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -215,9 +215,9 @@ func (alloc *Allocator) Lookup(ident string, r address.Range) (address.Address, } // Claim an address that we think we should own (Sync) -func (alloc *Allocator) Claim(ident string, addr address.Address, reclaim bool) error { +func (alloc *Allocator) Claim(ident string, addr address.Address, noErrorOnUnknown bool) error { resultChan := make(chan error) - op := &claim{resultChan: resultChan, ident: ident, addr: addr, reclaim: reclaim} + op := &claim{resultChan: resultChan, ident: ident, addr: addr, noErrorOnUnknown: noErrorOnUnknown} alloc.doOperation(op, &alloc.pendingClaims) return <-resultChan } diff --git a/ipam/claim.go b/ipam/claim.go index 2cb2c1f6..aa4ee17b 100644 --- a/ipam/claim.go +++ b/ipam/claim.go @@ -9,12 +9,13 @@ import ( ) type claim struct { - resultChan chan<- error - ident string - addr address.Address - reclaim bool + resultChan chan<- error + ident string + addr address.Address + noErrorOnUnknown bool } +// 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 if c.resultChan != nil { @@ -32,9 +33,7 @@ func (c *claim) sendResult(result error) { func (c *claim) Try(alloc *Allocator) bool { if !alloc.ring.Contains(c.addr) { // Address not within our universe; assume user knows what they are doing - if c.reclaim { - alloc.infof("Ignored address %s claimed by %s - not in our universe", c.addr, c.ident) - } + alloc.infof("Ignored address %s claimed by %s - not in our universe", c.addr, c.ident) c.sendResult(nil) return true } @@ -44,7 +43,7 @@ func (c *claim) Try(alloc *Allocator) bool { // success case router.UnknownPeerName: // If our ring doesn't know, it must be empty. - if c.reclaim { + if c.noErrorOnUnknown { alloc.infof("Claim %s for %s: address allocator still initializing; will try later.", c.addr, c.ident) c.sendResult(nil) // don't make the caller wait } else { @@ -55,7 +54,7 @@ func (c *claim) Try(alloc *Allocator) bool { alloc.debugf("requesting address %s from other peer %s", c.addr, owner) err := alloc.sendSpaceRequest(owner, address.NewRange(c.addr, 1)) if err != nil { // can't speak to owner right now - if c.reclaim { // don't hold up launch; figure it out later + if c.noErrorOnUnknown { alloc.infof("Claim %s for %s: %s; will try later.", c.addr, c.ident, err) c.sendResult(nil) } else { // just tell the user they can't do this. diff --git a/ipam/http.go b/ipam/http.go index e18d4caf..669bc41d 100644 --- a/ipam/http.go +++ b/ipam/http.go @@ -22,11 +22,11 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID vars := mux.Vars(r) ident := vars["id"] ipStr := vars["ip"] - reclaim := r.FormValue("reclaim") == "true" + noErrorOnUnknown := r.FormValue("noErrorOnUnknown") == "true" if ip, err := address.ParseIP(ipStr); err != nil { badRequest(w, err) return - } else if err := alloc.Claim(ident, ip, reclaim); err != nil { + } else if err := alloc.Claim(ident, ip, noErrorOnUnknown); err != nil { badRequest(w, fmt.Errorf("Unable to claim: %s", err)) return } diff --git a/weave b/weave index f7ad69b1..e3528961 100755 --- a/weave +++ b/weave @@ -815,7 +815,7 @@ delete_dns_fqdn() { ipam_reclaim() { for CIDR in $3 ; do # NB: CONTAINER_IP is the IP of the weave container; it is set by wait_for_status. - http_call_ip $CONTAINER_IP $HTTP_PORT PUT /ip/$1/${CIDR%/*}?reclaim=true + http_call_ip $CONTAINER_IP $HTTP_PORT PUT /ip/$1/${CIDR%/*}?noErrorOnUnknown=true done }