Skip to content

Commit

Permalink
Add the data-path-addr
Browse files Browse the repository at this point in the history
During configuration in SWARM mode is now possible to pass an additional
parameter --data-path-addr <ip|interface>.
The information is going to be used to configure which is the interface
that is going to be used for the data path for global scope drivers.
Up to now the only driver really using this extra parameter is the
overlay driver.

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
  • Loading branch information
Flavio Crisciani committed Apr 14, 2017
1 parent de0926b commit a0e0231
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
38 changes: 24 additions & 14 deletions libnetwork/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ type agent struct {
networkDB *networkdb.NetworkDB
bindAddr string
advertiseAddr string
dataPathAddr string
epTblCancel func()
driverCancelFuncs map[string][]func()
sync.Mutex
}

func (a *agent) dataPathAddress() string {
a.Lock()
defer a.Unlock()
if a.dataPathAddr != "" {
return a.dataPathAddr
}
return a.advertiseAddr
}

const libnetworkEPTable = "endpoint_table"

func getBindAddr(ifaceName string) (string, error) {
Expand Down Expand Up @@ -189,14 +199,16 @@ func (c *controller) agentSetup() error {
c.Unlock()
bindAddr := clusterProvider.GetLocalAddress()
advAddr := clusterProvider.GetAdvertiseAddress()
dataAddr := clusterProvider.GetDataPathAddress()
remote := clusterProvider.GetRemoteAddress()
remoteAddr, _, _ := net.SplitHostPort(remote)
listen := clusterProvider.GetListenAddress()
listenAddr, _, _ := net.SplitHostPort(listen)

logrus.Infof("Initializing Libnetwork Agent Listen-Addr=%s Local-addr=%s Adv-addr=%s Remote-addr =%s", listenAddr, bindAddr, advAddr, remoteAddr)
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)
if advAddr != "" && agent == nil {
if err := c.agentInit(listenAddr, bindAddr, advAddr); err != nil {
if err := c.agentInit(listenAddr, bindAddr, advAddr, dataAddr); err != nil {
logrus.Errorf("Error in agentInit : %v", err)
} else {
c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
Expand Down Expand Up @@ -262,7 +274,7 @@ func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error) {
return keys[1].Key, keys[1].LamportTime, nil
}

func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr string) error {
func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, dataPathAddr string) error {
if !c.isAgent() {
return nil
}
Expand Down Expand Up @@ -296,6 +308,7 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr st
networkDB: nDB,
bindAddr: bindAddr,
advertiseAddr: advertiseAddr,
dataPathAddr: dataPathAddr,
epTblCancel: cancel,
driverCancelFuncs: make(map[string][]func()),
}
Expand Down Expand Up @@ -336,25 +349,22 @@ func (c *controller) agentDriverNotify(d driverapi.Driver) {
return
}

d.DiscoverNew(discoverapi.NodeDiscovery, discoverapi.NodeDiscoveryData{
Address: agent.advertiseAddr,
if err := d.DiscoverNew(discoverapi.NodeDiscovery, discoverapi.NodeDiscoveryData{
Address: agent.dataPathAddress(),
BindAddress: agent.bindAddr,
Self: true,
})
}); err != nil {
logrus.Warnf("Failed the node discovery in driver: %v", err)
}

drvEnc := discoverapi.DriverEncryptionConfig{}
keys, tags := c.getKeys(subsysIPSec)
drvEnc.Keys = keys
drvEnc.Tags = tags

c.drvRegistry.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
err := driver.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc)
if err != nil {
logrus.Warnf("Failed to set datapath keys in driver %s: %v", name, err)
}
return false
})

if err := d.DiscoverNew(discoverapi.EncryptionKeysConfig, drvEnc); err != nil {
logrus.Warnf("Failed to set datapath keys in driver: %v", err)
}
}

func (c *controller) agentClose() {
Expand Down
1 change: 1 addition & 0 deletions libnetwork/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Provider interface {
GetLocalAddress() string
GetListenAddress() string
GetAdvertiseAddress() string
GetDataPathAddress() string
GetRemoteAddress() string
ListenClusterEvents() <-chan struct{}
AttachNetwork(string, string, []string) (*network.NetworkingConfig, error)
Expand Down
4 changes: 4 additions & 0 deletions libnetwork/cmd/dnet/dnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ func (d *dnetConnection) GetAdvertiseAddress() string {
return d.Orchestration.Bind
}

func (d *dnetConnection) GetDataPathAddress() string {
return d.Orchestration.Bind
}

func (d *dnetConnection) GetLocalAddress() string {
return d.Orchestration.Bind
}
Expand Down

0 comments on commit a0e0231

Please sign in to comment.