Skip to content

Commit 98dda7e

Browse files
authored
Merge pull request #1460 from mrjana/networkdb
Honor user provided listen address for gossip
2 parents 6dd4176 + 8b04ffb commit 98dda7e

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

agent.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ func (c *controller) agentSetup() error {
172172
advAddr := clusterProvider.GetAdvertiseAddress()
173173
remote := clusterProvider.GetRemoteAddress()
174174
remoteAddr, _, _ := net.SplitHostPort(remote)
175+
listen := clusterProvider.GetListenAddress()
176+
listenAddr, _, _ := net.SplitHostPort(listen)
175177

176-
logrus.Infof("Initializing Libnetwork Agent Local-addr=%s Adv-addr=%s Remote-addr =%s", bindAddr, advAddr, remoteAddr)
178+
logrus.Infof("Initializing Libnetwork Agent Listen-Addr=%s Local-addr=%s Adv-addr=%s Remote-addr =%s", listenAddr, bindAddr, advAddr, remoteAddr)
177179
if advAddr != "" && c.agent == nil {
178-
if err := c.agentInit(bindAddr, advAddr); err != nil {
180+
if err := c.agentInit(listenAddr, bindAddr, advAddr); err != nil {
179181
logrus.Errorf("Error in agentInit : %v", err)
180182
} else {
181183
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
@@ -236,7 +238,7 @@ func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
236238
return keys[1].Key, keys[1].LamportTime, nil
237239
}
238240

239-
func (c *controller) agentInit(bindAddrOrInterface, advertiseAddr string) error {
241+
func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr string) error {
240242
if !c.isAgent() {
241243
return nil
242244
}
@@ -252,6 +254,7 @@ func (c *controller) agentInit(bindAddrOrInterface, advertiseAddr string) error
252254
logrus.Info("Gossip cluster hostname ", nodeName)
253255

254256
nDB, err := networkdb.New(&networkdb.Config{
257+
BindAddr: listenAddr,
255258
AdvertiseAddr: advertiseAddr,
256259
NodeName: nodeName,
257260
Keys: keys,

cluster/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Provider interface {
1010
IsManager() bool
1111
IsAgent() bool
1212
GetLocalAddress() string
13+
GetListenAddress() string
1314
GetAdvertiseAddress() string
1415
GetRemoteAddress() string
1516
ListenClusterEvents() <-chan struct{}

cmd/dnet/dnet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ func (d *dnetConnection) GetLocalAddress() string {
316316
return d.Orchestration.Bind
317317
}
318318

319+
func (d *dnetConnection) GetListenAddress() string {
320+
return d.Orchestration.Bind
321+
}
322+
319323
func (d *dnetConnection) GetRemoteAddress() string {
320324
return d.Orchestration.Peer
321325
}

networkdb/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (nDB *NetworkDB) RemoveKey(key []byte) {
8686
func (nDB *NetworkDB) clusterInit() error {
8787
config := memberlist.DefaultLANConfig()
8888
config.Name = nDB.config.NodeName
89+
config.BindAddr = nDB.config.BindAddr
8990
config.AdvertiseAddr = nDB.config.AdvertiseAddr
9091

9192
if nDB.config.BindPort != 0 {

networkdb/networkdb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ type Config struct {
121121
// NodeName is the cluster wide unique name for this node.
122122
NodeName string
123123

124+
// BindAddr is the IP on which networkdb listens. It can be
125+
// 0.0.0.0 to listen on all addresses on the host.
126+
BindAddr string
127+
124128
// AdvertiseAddr is the node's IP address that we advertise for
125129
// cluster communication.
126130
AdvertiseAddr string

0 commit comments

Comments
 (0)