mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #32920 from fcrisciani/remote_addr
Change GetRemoteAddress to return an IP list
This commit is contained in:
commit
f0bb1d7a4a
5 changed files with 33 additions and 20 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -24,7 +24,7 @@ github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
|
|||
github.com/imdario/mergo 0.2.1
|
||||
|
||||
#get libnetwork packages
|
||||
github.com/docker/libnetwork 5dc95a3f9ce4b70bf08492ca37ec55c5b6d84975
|
||||
github.com/docker/libnetwork cace103704768d39bd88a23d0df76df125a0e39a
|
||||
github.com/docker/go-events 18b43f1bc85d9cdd42c05a6cd2d444c7a200a894
|
||||
github.com/armon/go-radix e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
|
||||
github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
||||
|
|
21
vendor/github.com/docker/libnetwork/agent.go
generated
vendored
21
vendor/github.com/docker/libnetwork/agent.go
generated
vendored
|
@ -207,13 +207,18 @@ func (c *controller) agentSetup() error {
|
|||
bindAddr := clusterProvider.GetLocalAddress()
|
||||
advAddr := clusterProvider.GetAdvertiseAddress()
|
||||
dataAddr := clusterProvider.GetDataPathAddress()
|
||||
remote := clusterProvider.GetRemoteAddress()
|
||||
remoteAddr, _, _ := net.SplitHostPort(remote)
|
||||
remoteList := clusterProvider.GetRemoteAddressList()
|
||||
remoteAddrList := make([]string, 0, len(remoteList))
|
||||
for _, remote := range remoteList {
|
||||
addr, _, _ := net.SplitHostPort(remote)
|
||||
remoteAddrList = append(remoteAddrList, addr)
|
||||
}
|
||||
|
||||
listen := clusterProvider.GetListenAddress()
|
||||
listenAddr, _, _ := net.SplitHostPort(listen)
|
||||
|
||||
logrus.Infof("Initializing Libnetwork Agent Listen-Addr=%s Local-addr=%s Adv-addr=%s Data-addr=%s Remote-addr=%s",
|
||||
listenAddr, bindAddr, advAddr, dataAddr, remoteAddr)
|
||||
logrus.Infof("Initializing Libnetwork Agent Listen-Addr=%s Local-addr=%s Adv-addr=%s Data-addr=%s Remote-addr-list=%v",
|
||||
listenAddr, bindAddr, advAddr, dataAddr, remoteAddrList)
|
||||
if advAddr != "" && agent == nil {
|
||||
if err := c.agentInit(listenAddr, bindAddr, advAddr, dataAddr); err != nil {
|
||||
logrus.Errorf("Error in agentInit : %v", err)
|
||||
|
@ -227,8 +232,8 @@ func (c *controller) agentSetup() error {
|
|||
}
|
||||
}
|
||||
|
||||
if remoteAddr != "" {
|
||||
if err := c.agentJoin(remoteAddr); err != nil {
|
||||
if len(remoteAddrList) > 0 {
|
||||
if err := c.agentJoin(remoteAddrList); err != nil {
|
||||
logrus.Errorf("Error in joining gossip cluster : %v(join will be retried in background)", err)
|
||||
}
|
||||
}
|
||||
|
@ -342,12 +347,12 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *controller) agentJoin(remote string) error {
|
||||
func (c *controller) agentJoin(remoteAddrList []string) error {
|
||||
agent := c.getAgent()
|
||||
if agent == nil {
|
||||
return nil
|
||||
}
|
||||
return agent.networkDB.Join([]string{remote})
|
||||
return agent.networkDB.Join(remoteAddrList)
|
||||
}
|
||||
|
||||
func (c *controller) agentDriverNotify(d driverapi.Driver) {
|
||||
|
|
2
vendor/github.com/docker/libnetwork/cluster/provider.go
generated
vendored
2
vendor/github.com/docker/libnetwork/cluster/provider.go
generated
vendored
|
@ -13,7 +13,7 @@ type Provider interface {
|
|||
GetListenAddress() string
|
||||
GetAdvertiseAddress() string
|
||||
GetDataPathAddress() string
|
||||
GetRemoteAddress() string
|
||||
GetRemoteAddressList() []string
|
||||
ListenClusterEvents() <-chan struct{}
|
||||
AttachNetwork(string, string, []string) (*network.NetworkingConfig, error)
|
||||
DetachNetwork(string, string) error
|
||||
|
|
Loading…
Add table
Reference in a new issue