Added 'ContainerDestroyed()' callback from docker client
This commit is contained in:
1 parent
2f885a7906
commit
b2b293a8ee
5 files changed
+22
-7
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {}
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user