Browse Source

Add agent initialization wait method in controller

Agent initialization wait method is added to make sure callers for
controller methods which depend on agent initialization to be complete
can wait on it.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Jana Radhakrishnan 9 năm trước cách đây
mục cha
commit
a63fca344f
1 tập tin đã thay đổi với 15 bổ sung0 xóa
  1. 15 0
      libnetwork/controller.go

+ 15 - 0
libnetwork/controller.go

@@ -114,6 +114,9 @@ type NetworkController interface {
 
 
 	// SetClusterProvider sets cluster provider
 	// SetClusterProvider sets cluster provider
 	SetClusterProvider(provider cluster.Provider)
 	SetClusterProvider(provider cluster.Provider)
+
+	// Wait for agent initialization complete in libnetwork controller
+	AgentInitWait()
 }
 }
 
 
 // NetworkWalker is a client provided function which will be used to walk the Networks.
 // NetworkWalker is a client provided function which will be used to walk the Networks.
@@ -143,6 +146,7 @@ type controller struct {
 	ingressSandbox  *sandbox
 	ingressSandbox  *sandbox
 	sboxOnce        sync.Once
 	sboxOnce        sync.Once
 	agent           *agent
 	agent           *agent
+	agentInitDone   chan struct{}
 	sync.Mutex
 	sync.Mutex
 }
 }
 
 
@@ -159,6 +163,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
 		sandboxes:       sandboxTable{},
 		sandboxes:       sandboxTable{},
 		svcRecords:      make(map[string]svcInfo),
 		svcRecords:      make(map[string]svcInfo),
 		serviceBindings: make(map[string]*service),
 		serviceBindings: make(map[string]*service),
+		agentInitDone:   make(chan struct{}),
 	}
 	}
 
 
 	if err := c.initStores(); err != nil {
 	if err := c.initStores(); err != nil {
@@ -248,6 +253,10 @@ func (c *controller) clusterAgentInit() {
 							}
 							}
 							return false
 							return false
 						})
 						})
+
+						if c.agent != nil {
+							close(c.agentInitDone)
+						}
 					}
 					}
 				}
 				}
 				if remoteAddr != "" {
 				if remoteAddr != "" {
@@ -262,6 +271,12 @@ func (c *controller) clusterAgentInit() {
 	}
 	}
 }
 }
 
 
+// AgentInitWait waits for agent initialization to be completed in the
+// controller.
+func (c *controller) AgentInitWait() {
+	<-c.agentInitDone
+}
+
 func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
 func (c *controller) makeDriverConfig(ntype string) map[string]interface{} {
 	if c.cfg == nil {
 	if c.cfg == nil {
 		return nil
 		return nil