Browse code

Change GetRemoteAddr to return all managers

Respect the new provider interface

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>

Flavio Crisciani authored on 2017/04/28 09:06:16
Showing 2 changed files
... ...
@@ -280,27 +280,29 @@ func (c *Cluster) GetDataPathAddress() string {
280 280
 	return ""
281 281
 }
282 282
 
283
-// GetRemoteAddress returns a known advertise address of a remote manager if
283
+// GetRemoteAddressList returns the advertise address for each of the remote managers if
284 284
 // available.
285
-// todo: change to array/connect with info
286
-func (c *Cluster) GetRemoteAddress() string {
285
+func (c *Cluster) GetRemoteAddressList() []string {
287 286
 	c.mu.RLock()
288 287
 	defer c.mu.RUnlock()
289
-	return c.getRemoteAddress()
288
+	return c.getRemoteAddressList()
290 289
 }
291 290
 
292
-func (c *Cluster) getRemoteAddress() string {
291
+func (c *Cluster) getRemoteAddressList() []string {
293 292
 	state := c.currentNodeState()
294 293
 	if state.swarmNode == nil {
295
-		return ""
294
+		return []string{}
296 295
 	}
296
+
297 297
 	nodeID := state.swarmNode.NodeID()
298
-	for _, r := range state.swarmNode.Remotes() {
298
+	remotes := state.swarmNode.Remotes()
299
+	addressList := make([]string, 0, len(remotes))
300
+	for _, r := range remotes {
299 301
 		if r.NodeID != nodeID {
300
-			return r.Addr
302
+			addressList = append(addressList, r.Addr)
301 303
 		}
302 304
 	}
303
-	return ""
305
+	return addressList
304 306
 }
305 307
 
306 308
 // ListenClusterEvents returns a channel that receives messages on cluster
... ...
@@ -271,7 +271,13 @@ func (n *nodeRunner) enableReconnectWatcher() {
271 271
 		if n.stopping {
272 272
 			return
273 273
 		}
274
-		config.RemoteAddr = n.cluster.getRemoteAddress()
274
+		remotes := n.cluster.getRemoteAddressList()
275
+		if len(remotes) > 0 {
276
+			config.RemoteAddr = remotes[0]
277
+		} else {
278
+			config.RemoteAddr = ""
279
+		}
280
+
275 281
 		config.joinAddr = config.RemoteAddr
276 282
 		if err := n.start(config); err != nil {
277 283
 			n.err = err