From 18098ab1c8614d0d5dd59e6283b1013405c04857 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Wed, 5 Apr 2017 10:38:24 -0700 Subject: [PATCH] Add AgentStopWait method - to signal when the networking cluster agent is stopped Signed-off-by: Alessandro Boch --- libnetwork/agent.go | 1 + libnetwork/controller.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libnetwork/agent.go b/libnetwork/agent.go index feda2c2846..ff1869055f 100644 --- a/libnetwork/agent.go +++ b/libnetwork/agent.go @@ -218,6 +218,7 @@ func (c *controller) agentSetup() error { if c.agent != nil && c.agentInitDone != nil { close(c.agentInitDone) c.agentInitDone = nil + c.agentStopDone = make(chan struct{}) } c.Unlock() diff --git a/libnetwork/controller.go b/libnetwork/controller.go index e2d6fc5ecb..0674af516d 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -127,6 +127,9 @@ type NetworkController interface { // Wait for agent initialization complete in libnetwork controller AgentInitWait() + // Wait for agent to stop if running + AgentStopWait() + // SetKeys configures the encryption key for gossip and overlay data path SetKeys(keys []*types.EncryptionKey) error } @@ -160,6 +163,7 @@ type controller struct { agent *agent networkLocker *locker.Locker agentInitDone chan struct{} + agentStopDone chan struct{} keys []*types.EncryptionKey clusterConfigAvailable bool sync.Mutex @@ -337,6 +341,14 @@ func (c *controller) clusterAgentInit() { // service bindings c.agentClose() c.cleanupServiceBindings("") + + c.Lock() + if c.agentStopDone != nil { + close(c.agentStopDone) + c.agentStopDone = nil + } + c.Unlock() + return } } @@ -354,6 +366,15 @@ func (c *controller) AgentInitWait() { } } +func (c *controller) AgentStopWait() { + c.Lock() + agentStopDone := c.agentStopDone + c.Unlock() + if agentStopDone != nil { + <-agentStopDone + } +} + func (c *controller) makeDriverConfig(ntype string) map[string]interface{} { if c.cfg == nil { return nil