From 2f885a790668681e123576e93a1de3be31b5bded Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 28 Aug 2015 14:18:17 +0100 Subject: [PATCH] Reclaim all addresses on restart --- ipam/claim.go | 4 ++++ site/features.md | 15 ++++++++++++--- weave | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ipam/claim.go b/ipam/claim.go index 20ec6519..0173af6a 100644 --- a/ipam/claim.go +++ b/ipam/claim.go @@ -40,6 +40,9 @@ func (c *claim) Try(alloc *Allocator) bool { alloc.establishRing() + // If we had heard that this container died, resurrect it + delete(alloc.dead, c.ident) // (delete is no-op if key not in map) + switch owner := alloc.ring.Owner(c.addr); owner { case alloc.ourName: // success @@ -78,6 +81,7 @@ func (c *claim) Try(alloc *Allocator) bool { } case c.ident: // same identifier is claiming same address; that's OK + alloc.debugln("Re-Claimed", c.addr, "for", c.ident) c.sendResult(nil) default: // Addr already owned by container on this machine diff --git a/site/features.md b/site/features.md index 02a8b2a4..3612a151 100644 --- a/site/features.md +++ b/site/features.md @@ -167,12 +167,21 @@ the weave network: host1$ weave ps a1 a1 16:c0:6f:5d:c5:73 10.32.0.3/12 -There is also a `weave restart` command, if you are not using the -weave Docker API proxy: +It works the same if you stop and immediately restart: + + host1$ docker stop a1 + host1$ docker start a1 + +However, additional addresses added with the `weave attach` command +will not be retained. + +There is also a `weave restart` command, which does re-attach all +current IP addresses: host1$ weave restart b1 -(note that the IP address is held for a limited time - currently five seconds) +(note that the IP addresses are held for a limited time - currently +five seconds) ### Naming and discovery diff --git a/weave b/weave index 65172f01..8128bd44 100755 --- a/weave +++ b/weave @@ -2036,6 +2036,10 @@ EOF create_bridge ALL_CIDRS=$(with_container_addresses echo_cidrs $1) RES=$(docker restart "$1") + CONTAINER=$(container_id $1) + for CIDR in $ALL_CIDRS ; do + call_weave PUT /ip/$CONTAINER/${CIDR%/*} + done with_container_netns_or_die $1 attach $ALL_CIDRS when_weave_running with_container_fqdn $1 put_dns_fqdn $ALL_CIDRS echo $RES