Change GetRemoteAddr to return all managers

Respect the new provider interface

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
Flavio Crisciani 2017-04-27 17:06:16 -07:00
parent 68a5336b61
commit 441e861095
No known key found for this signature in database
GPG key ID: 28CAFCE754CF3A48
2 changed files with 18 additions and 10 deletions

View file

@ -280,27 +280,29 @@ func (c *Cluster) GetDataPathAddress() string {
return ""
}
// GetRemoteAddress returns a known advertise address of a remote manager if
// GetRemoteAddressList returns the advertise address for each of the remote managers if
// available.
// todo: change to array/connect with info
func (c *Cluster) GetRemoteAddress() string {
func (c *Cluster) GetRemoteAddressList() []string {
c.mu.RLock()
defer c.mu.RUnlock()
return c.getRemoteAddress()
return c.getRemoteAddressList()
}
func (c *Cluster) getRemoteAddress() string {
func (c *Cluster) getRemoteAddressList() []string {
state := c.currentNodeState()
if state.swarmNode == nil {
return ""
return []string{}
}
nodeID := state.swarmNode.NodeID()
for _, r := range state.swarmNode.Remotes() {
remotes := state.swarmNode.Remotes()
addressList := make([]string, 0, len(remotes))
for _, r := range remotes {
if r.NodeID != nodeID {
return r.Addr
addressList = append(addressList, r.Addr)
}
}
return ""
return addressList
}
// ListenClusterEvents returns a channel that receives messages on cluster

View file

@ -271,7 +271,13 @@ func (n *nodeRunner) enableReconnectWatcher() {
if n.stopping {
return
}
config.RemoteAddr = n.cluster.getRemoteAddress()
remotes := n.cluster.getRemoteAddressList()
if len(remotes) > 0 {
config.RemoteAddr = remotes[0]
} else {
config.RemoteAddr = ""
}
config.joinAddr = config.RemoteAddr
if err := n.start(config); err != nil {
n.err = err