Skip to content

Commit

Permalink
Merge pull request #1953 from fcrisciani/netdb-backport-17.06
Browse files Browse the repository at this point in the history
[17.06 backport] NetworkDB fixes backport
  • Loading branch information
mavenugo authored Sep 23, 2017
2 parents 9397626 + 2966d33 commit 25eed4b
Show file tree
Hide file tree
Showing 17 changed files with 765 additions and 487 deletions.
36 changes: 16 additions & 20 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ func (c *controller) handleKeyChange(keys []*types.EncryptionKey) error {
a.networkDB.SetKey(added)
}

key, tag, err := c.getPrimaryKeyTag(subsysGossip)
key, _, err := c.getPrimaryKeyTag(subsysGossip)
if err != nil {
return err
}
a.networkDB.SetPrimaryKey(key)

key, tag, err = c.getPrimaryKeyTag(subsysIPSec)
key, tag, err := c.getPrimaryKeyTag(subsysIPSec)
if err != nil {
return err
}
Expand Down Expand Up @@ -286,12 +286,12 @@ func (c *controller) agentInit(listenAddr, bindAddrOrInterface, advertiseAddr, d
nodeName := hostname + "-" + stringid.TruncateID(stringid.GenerateRandomID())
logrus.Info("Gossip cluster hostname ", nodeName)

nDB, err := networkdb.New(&networkdb.Config{
BindAddr: listenAddr,
AdvertiseAddr: advertiseAddr,
NodeName: nodeName,
Keys: keys,
})
netDBConf := networkdb.DefaultConfig()
netDBConf.NodeName = nodeName
netDBConf.BindAddr = listenAddr
netDBConf.AdvertiseAddr = advertiseAddr
netDBConf.Keys = keys
nDB, err := networkdb.New(netDBConf)

if err != nil {
return err
Expand Down Expand Up @@ -383,15 +383,11 @@ func (c *controller) agentClose() {

agent.Lock()
for _, cancelFuncs := range agent.driverCancelFuncs {
for _, cancel := range cancelFuncs {
cancelList = append(cancelList, cancel)
}
cancelList = append(cancelList, cancelFuncs...)
}

// Add also the cancel functions for the network db
for _, cancel := range agent.coreCancelFuncs {
cancelList = append(cancelList, cancel)
}
cancelList = append(cancelList, agent.coreCancelFuncs...)
agent.Unlock()

for _, cancel := range cancelList {
Expand Down Expand Up @@ -885,31 +881,31 @@ func (c *controller) handleEpTableEvent(ev events.Event) {
}

if isAdd {
logrus.Debugf("handleEpTableEvent ADD %s R:%v", isAdd, eid, epRec)
logrus.Debugf("handleEpTableEvent ADD %s R:%v", eid, epRec)
if svcID != "" {
// This is a remote task part of a service
if err := c.addServiceBinding(svcName, svcID, nid, eid, containerName, vip, ingressPorts, serviceAliases, taskAliases, ip, "handleEpTableEvent"); err != nil {
logrus.Errorf("failed adding service binding for %s epRec:%v err:%s", eid, epRec, err)
logrus.Errorf("failed adding service binding for %s epRec:%v err:%v", eid, epRec, err)
return
}
} else {
// This is a remote container simply attached to an attachable network
if err := c.addContainerNameResolution(nid, eid, containerName, taskAliases, ip, "handleEpTableEvent"); err != nil {
logrus.Errorf("failed adding service binding for %s epRec:%v err:%s", eid, epRec, err)
logrus.Errorf("failed adding container name resolution for %s epRec:%v err:%v", eid, epRec, err)
}
}
} else {
logrus.Debugf("handleEpTableEvent DEL %s R:%v", isAdd, eid, epRec)
logrus.Debugf("handleEpTableEvent DEL %s R:%v", eid, epRec)
if svcID != "" {
// This is a remote task part of a service
if err := c.rmServiceBinding(svcName, svcID, nid, eid, containerName, vip, ingressPorts, serviceAliases, taskAliases, ip, "handleEpTableEvent", true); err != nil {
logrus.Errorf("failed removing service binding for %s epRec:%v err:%s", eid, epRec, err)
logrus.Errorf("failed removing service binding for %s epRec:%v err:%v", eid, epRec, err)
return
}
} else {
// This is a remote container simply attached to an attachable network
if err := c.delContainerNameResolution(nid, eid, containerName, taskAliases, ip, "handleEpTableEvent"); err != nil {
logrus.Errorf("failed adding service binding for %s epRec:%v err:%s", eid, epRec, err)
logrus.Errorf("failed removing container name resolution for %s epRec:%v err:%v", eid, epRec, err)
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/dnet/dnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,7 @@ func startTestDriver() error {
return err
}

if err := ioutil.WriteFile("/etc/docker/plugins/test.spec", []byte(server.URL), 0644); err != nil {
return err
}

return nil
return ioutil.WriteFile("/etc/docker/plugins/test.spec", []byte(server.URL), 0644)
}

func newDnetConnection(val string) (*dnetConnection, error) {
Expand Down
6 changes: 1 addition & 5 deletions drivers/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,7 @@ func (d *driver) createNetwork(config *networkConfiguration) error {

// Apply the prepared list of steps, and abort at the first error.
bridgeSetup.queueStep(setupDeviceUp)
if err = bridgeSetup.apply(); err != nil {
return err
}

return nil
return bridgeSetup.apply()
}

func (d *driver) DeleteNetwork(nid string) error {
Expand Down
11 changes: 2 additions & 9 deletions drivers/bridge/setup_ip_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ func setupIPTablesInternal(bridgeIface string, addr net.Addr, icc, ipmasq, hairp
}

// Set Accept on all non-intercontainer outgoing packets.
if err := programChainRule(outRule, "ACCEPT NON_ICC OUTGOING", enable); err != nil {
return err
}

return nil
return programChainRule(outRule, "ACCEPT NON_ICC OUTGOING", enable)
}

func programChainRule(rule iptRule, ruleDescr string, insert bool) error {
Expand Down Expand Up @@ -304,10 +300,7 @@ func setupInternalNetworkRules(bridgeIface string, addr net.Addr, icc, insert bo
return err
}
// Set Inter Container Communication.
if err := setIcc(bridgeIface, icc, insert); err != nil {
return err
}
return nil
return setIcc(bridgeIface, icc, insert)
}

func clearEndpointConnections(nlh *netlink.Handle, ep *bridgeEndpoint) {
Expand Down
11 changes: 2 additions & 9 deletions drivers/overlay/ov_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,15 @@ func (d *driver) deleteEndpointFromStore(e *endpoint) error {
return fmt.Errorf("overlay local store not initialized, ep not deleted")
}

if err := d.localStore.DeleteObjectAtomic(e); err != nil {
return err
}

return nil
return d.localStore.DeleteObjectAtomic(e)
}

func (d *driver) writeEndpointToStore(e *endpoint) error {
if d.localStore == nil {
return fmt.Errorf("overlay local store not initialized, ep not added")
}

if err := d.localStore.PutObjectAtomic(e); err != nil {
return err
}
return nil
return d.localStore.PutObjectAtomic(e)
}

func (ep *endpoint) DataScope() string {
Expand Down
11 changes: 2 additions & 9 deletions drivers/solaris/overlay/ov_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,15 @@ func (d *driver) deleteEndpointFromStore(e *endpoint) error {
return fmt.Errorf("overlay local store not initialized, ep not deleted")
}

if err := d.localStore.DeleteObjectAtomic(e); err != nil {
return err
}

return nil
return d.localStore.DeleteObjectAtomic(e)
}

func (d *driver) writeEndpointToStore(e *endpoint) error {
if d.localStore == nil {
return fmt.Errorf("overlay local store not initialized, ep not added")
}

if err := d.localStore.PutObjectAtomic(e); err != nil {
return err
}
return nil
return d.localStore.PutObjectAtomic(e)
}

func (ep *endpoint) DataScope() string {
Expand Down
6 changes: 1 addition & 5 deletions endpoint_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ func (ep *endpoint) Info() EndpointInfo {
return ep
}

if epi := sb.getEndpoint(ep.ID()); epi != nil {
return epi
}

return nil
return sb.getEndpoint(ep.ID())
}

func (ep *endpoint) Iface() InterfaceInfo {
Expand Down
11 changes: 2 additions & 9 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,7 @@ func (c *ChainInfo) Forward(action Action, ip net.IP, port int, proto, destAddr
"--dport", strconv.Itoa(destPort),
"-j", "MASQUERADE",
}
if err := ProgramRule(Nat, "POSTROUTING", action, args); err != nil {
return err
}

return nil
return ProgramRule(Nat, "POSTROUTING", action, args)
}

// Link adds reciprocal ACCEPT rule for two supplied IP addresses.
Expand All @@ -301,10 +297,7 @@ func (c *ChainInfo) Link(action Action, ip1, ip2 net.IP, port int, proto string,
// reverse
args[7], args[9] = args[9], args[7]
args[10] = "--sport"
if err := ProgramRule(Filter, c.Name, action, args); err != nil {
return err
}
return nil
return ProgramRule(Filter, c.Name, action, args)
}

// ProgramRule adds the rule specified by args only if the
Expand Down
2 changes: 2 additions & 0 deletions networkdb/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (nDB *NetworkDB) sendTableEvent(event TableEvent_Type, nid string, tname st
TableName: tname,
Key: key,
Value: entry.value,
// The duration in second is a float that below would be truncated
ResidualReapTime: int32(entry.reapTime.Seconds()),
}

raw, err := encodeMessage(MessageTypeTableEvent, &tEvent)
Expand Down
Loading

0 comments on commit 25eed4b

Please sign in to comment.