diff --git a/common/docker/client.go b/common/docker/client.go index 5bd04f3f..cc845c28 100644 --- a/common/docker/client.go +++ b/common/docker/client.go @@ -14,6 +14,7 @@ import ( type ContainerObserver interface { ContainerStarted(ident string) ContainerDied(ident string) + ContainerDestroyed(ident string) } type Client struct { @@ -82,11 +83,11 @@ func (c *Client) AddObserver(ob ContainerObserver) error { for event := range events { switch event.Status { case "start": - id := event.ID - ob.ContainerStarted(id) + ob.ContainerStarted(event.ID) case "die": - id := event.ID - ob.ContainerDied(id) + ob.ContainerDied(event.ID) + case "destroy": + ob.ContainerDestroyed(event.ID) } } }() diff --git a/ipam/allocator.go b/ipam/allocator.go index 069ea126..fb5e6cd2 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -239,6 +239,17 @@ func (alloc *Allocator) ContainerDied(ident string) { } } +// ContainerDestroyed called from the updater interface. Async. +func (alloc *Allocator) ContainerDestroyed(ident string) { + alloc.actionChan <- func() { + if _, found := alloc.lookupOwned(ident, alloc.universe); found { + alloc.debugln("Container", ident, "destroyed; removing addresses") + alloc.delete(ident) + delete(alloc.dead, ident) + } + } +} + func (alloc *Allocator) removeDeadContainers() { cutoff := alloc.now().Add(-containerDiedTimeout) for ident, timeOfDeath := range alloc.dead { diff --git a/nameserver/nameserver.go b/nameserver/nameserver.go index 201bda3b..ef303728 100644 --- a/nameserver/nameserver.go +++ b/nameserver/nameserver.go @@ -121,7 +121,8 @@ func (n *Nameserver) ReverseLookup(ip address.Address) (string, error) { return match.Hostname, nil } -func (n *Nameserver) ContainerStarted(ident string) {} +func (n *Nameserver) ContainerStarted(ident string) {} +func (n *Nameserver) ContainerDestroyed(ident string) {} func (n *Nameserver) ContainerDied(ident string) { n.Lock() diff --git a/plugin/net/watcher.go b/plugin/net/watcher.go index 05241d4f..935d4ed8 100644 --- a/plugin/net/watcher.go +++ b/plugin/net/watcher.go @@ -55,3 +55,5 @@ func (w *watcher) ContainerDied(id string) { // don't need to do this as WeaveDNS removes names on container died anyway // (note by the time we get this event we can't see the EndpointID) } + +func (w *watcher) ContainerDestroyed(id string) {} diff --git a/proxy/proxy.go b/proxy/proxy.go index c316797e..1045fd51 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -458,8 +458,8 @@ func (proxy *Proxy) waitForStartByIdent(ident string) error { return nil } -func (proxy *Proxy) ContainerDied(ident string) { -} +func (proxy *Proxy) ContainerDied(ident string) {} +func (proxy *Proxy) ContainerDestroyed(ident string) {} // Check if this container needs to be attached, and return nil on success or not needed. func (proxy *Proxy) attach(containerID string, orDie bool) error {