mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #17381 from mavenugo/rc3v1
Vendoring in libnetwork with fixes for issues identified in RC1 & RC2
This commit is contained in:
commit
91de5ddf18
10 changed files with 144 additions and 30 deletions
|
@ -21,7 +21,7 @@ clone git github.com/vdemeester/shakers 3c10293ce22b900c27acad7b28656196fcc2f73b
|
|||
clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git
|
||||
|
||||
#get libnetwork packages
|
||||
clone git github.com/docker/libnetwork bf041154d27ed34ed39722328c8f1b0144a56fe2
|
||||
clone git github.com/docker/libnetwork c92c21bca42a3581fd108d3222848faa16372249
|
||||
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
|
||||
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
|
||||
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4
|
||||
|
|
|
@ -178,7 +178,7 @@ func New(cfgOptions ...config.Option) (NetworkController, error) {
|
|||
if err := c.initDiscovery(cfg.Cluster.Watcher); err != nil {
|
||||
// Failing to initalize discovery is a bad situation to be in.
|
||||
// But it cannot fail creating the Controller
|
||||
log.Debugf("Failed to Initialize Discovery : %v", err)
|
||||
log.Errorf("Failed to Initialize Discovery : %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ func makeDefaultScopes() map[string]*ScopeCfg {
|
|||
def := make(map[string]*ScopeCfg)
|
||||
def[LocalScope] = &ScopeCfg{
|
||||
Client: ScopeClientCfg{
|
||||
Provider: "boltdb",
|
||||
Provider: string(store.BOLTDB),
|
||||
Address: defaultPrefix + "/local-kv.db",
|
||||
Config: &store.Config{
|
||||
Bucket: "libnetwork",
|
||||
|
@ -144,7 +144,8 @@ func makeDefaultScopes() map[string]*ScopeCfg {
|
|||
return def
|
||||
}
|
||||
|
||||
var rootChain = []string{"docker", "network", "v1.0"}
|
||||
var defaultRootChain = []string{"docker", "network", "v1.0"}
|
||||
var rootChain = defaultRootChain
|
||||
|
||||
func init() {
|
||||
consul.Register()
|
||||
|
@ -195,6 +196,7 @@ func ParseKey(key string) ([]string, error) {
|
|||
|
||||
// newClient used to connect to KV Store
|
||||
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error) {
|
||||
|
||||
if cached && scope != LocalScope {
|
||||
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
|
||||
}
|
||||
|
@ -203,7 +205,21 @@ func newClient(scope string, kv string, addr string, config *store.Config, cache
|
|||
config = &store.Config{}
|
||||
}
|
||||
|
||||
addrs := strings.Split(addr, ",")
|
||||
var addrs []string
|
||||
|
||||
if kv == string(store.BOLTDB) {
|
||||
// Parse file path
|
||||
addrs = strings.Split(addr, ",")
|
||||
} else {
|
||||
// Parse URI
|
||||
parts := strings.SplitN(addr, "/", 2)
|
||||
addrs = strings.Split(parts[0], ",")
|
||||
|
||||
// Add the custom prefix to the root chain
|
||||
if len(parts) == 2 {
|
||||
rootChain = append([]string{parts[1]}, defaultRootChain...)
|
||||
}
|
||||
}
|
||||
|
||||
store, err := libkv.NewStore(store.Backend(kv), addrs, config)
|
||||
if err != nil {
|
||||
|
|
|
@ -58,6 +58,8 @@ func (sb *sandbox) setupDefaultGW(srcEp *endpoint) error {
|
|||
}
|
||||
}
|
||||
|
||||
createOptions = append(createOptions, CreateOptionAnonymous())
|
||||
|
||||
eplen := gwEPlen
|
||||
if len(sb.containerID) < gwEPlen {
|
||||
eplen = len(sb.containerID)
|
||||
|
|
|
@ -118,10 +118,12 @@ func (d *driver) Leave(nid, eid string) error {
|
|||
return fmt.Errorf("could not find network with id %s", nid)
|
||||
}
|
||||
|
||||
d.notifyCh <- ovNotify{
|
||||
action: "leave",
|
||||
nid: nid,
|
||||
eid: eid,
|
||||
if d.notifyCh != nil {
|
||||
d.notifyCh <- ovNotify{
|
||||
action: "leave",
|
||||
nid: nid,
|
||||
eid: eid,
|
||||
}
|
||||
}
|
||||
|
||||
n.leaveSandbox()
|
||||
|
|
|
@ -2,6 +2,7 @@ package overlay
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
@ -120,8 +121,30 @@ func (d *driver) Type() string {
|
|||
return networkType
|
||||
}
|
||||
|
||||
func validateSelf(node string) error {
|
||||
advIP := net.ParseIP(node)
|
||||
if advIP == nil {
|
||||
return fmt.Errorf("invalid self address (%s)", node)
|
||||
}
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to get interface addresses %v", err)
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
ip, _, err := net.ParseCIDR(addr.String())
|
||||
if err == nil && ip.Equal(advIP) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Multi-Host overlay networking requires cluster-advertise(%s) to be configured with a local ip-address that is reachable within the cluster", advIP.String())
|
||||
}
|
||||
|
||||
func (d *driver) nodeJoin(node string, self bool) {
|
||||
if self && !d.isSerfAlive() {
|
||||
if err := validateSelf(node); err != nil {
|
||||
logrus.Errorf("%s", err.Error())
|
||||
}
|
||||
d.Lock()
|
||||
d.bindAddress = node
|
||||
d.Unlock()
|
||||
|
|
|
@ -106,6 +106,51 @@ func (ep *endpoint) UnmarshalJSON(b []byte) (err error) {
|
|||
|
||||
if v, ok := epMap["generic"]; ok {
|
||||
ep.generic = v.(map[string]interface{})
|
||||
|
||||
if opt, ok := ep.generic[netlabel.PortMap]; ok {
|
||||
pblist := []types.PortBinding{}
|
||||
|
||||
for i := 0; i < len(opt.([]interface{})); i++ {
|
||||
pb := types.PortBinding{}
|
||||
tmp := opt.([]interface{})[i].(map[string]interface{})
|
||||
|
||||
bytes, err := json.Marshal(tmp)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
break
|
||||
}
|
||||
err = json.Unmarshal(bytes, &pb)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
break
|
||||
}
|
||||
pblist = append(pblist, pb)
|
||||
}
|
||||
ep.generic[netlabel.PortMap] = pblist
|
||||
}
|
||||
|
||||
if opt, ok := ep.generic[netlabel.ExposedPorts]; ok {
|
||||
tplist := []types.TransportPort{}
|
||||
|
||||
for i := 0; i < len(opt.([]interface{})); i++ {
|
||||
tp := types.TransportPort{}
|
||||
tmp := opt.([]interface{})[i].(map[string]interface{})
|
||||
|
||||
bytes, err := json.Marshal(tmp)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
break
|
||||
}
|
||||
err = json.Unmarshal(bytes, &tp)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
break
|
||||
}
|
||||
tplist = append(tplist, tp)
|
||||
}
|
||||
ep.generic[netlabel.ExposedPorts] = tplist
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := epMap["anonymous"]; ok {
|
||||
|
@ -345,7 +390,7 @@ func (ep *endpoint) sbJoin(sbox Sandbox, options ...EndpointOption) error {
|
|||
if ip := ep.getFirstInterfaceAddress(); ip != nil {
|
||||
address = ip.String()
|
||||
}
|
||||
if err = sb.updateHostsFile(address, network.getSvcRecords()); err != nil {
|
||||
if err = sb.updateHostsFile(address, network.getSvcRecords(ep)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -467,8 +512,7 @@ func (ep *endpoint) sbLeave(sbox Sandbox, options ...EndpointOption) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// unwatch for service records
|
||||
n.getController().unWatchSvcRecord(ep)
|
||||
sb.deleteHostsEntries(n.getSvcRecords(ep))
|
||||
|
||||
if sb.needDefaultGW() {
|
||||
ep := sb.getEPwithoutGateway()
|
||||
|
@ -501,17 +545,6 @@ func (ep *endpoint) Delete() error {
|
|||
}
|
||||
ep.Unlock()
|
||||
|
||||
if err = n.getEpCnt().DecEndpointCnt(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if e := n.getEpCnt().IncEndpointCnt(); e != nil {
|
||||
log.Warnf("failed to update network %s : %v", n.name, e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err = n.getController().deleteFromStore(ep); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -524,6 +557,20 @@ func (ep *endpoint) Delete() error {
|
|||
}
|
||||
}()
|
||||
|
||||
if err = n.getEpCnt().DecEndpointCnt(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if e := n.getEpCnt().IncEndpointCnt(); e != nil {
|
||||
log.Warnf("failed to update network %s : %v", n.name, e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// unwatch for service records
|
||||
n.getController().unWatchSvcRecord(ep)
|
||||
|
||||
if err = ep.deleteEndpoint(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -84,10 +84,6 @@ func (a *Allocator) refresh(as string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := a.updateBitMasks(aSpace); err != nil {
|
||||
return fmt.Errorf("error updating bit masks during init: %v", err)
|
||||
}
|
||||
|
||||
a.Lock()
|
||||
a.addrSpaces[as] = aSpace
|
||||
a.Unlock()
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
@ -685,6 +686,14 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
|
|||
}
|
||||
}()
|
||||
|
||||
// Watch for service records
|
||||
n.getController().watchSvcRecord(ep)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
n.getController().unWatchSvcRecord(ep)
|
||||
}
|
||||
}()
|
||||
|
||||
// Increment endpoint count to indicate completion of endpoint addition
|
||||
if err = n.getEpCnt().IncEndpointCnt(); err != nil {
|
||||
return nil, err
|
||||
|
@ -768,6 +777,12 @@ func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool
|
|||
var recs []etchosts.Record
|
||||
if iface := ep.Iface(); iface.Address() != nil {
|
||||
if isAdd {
|
||||
// If we already have this endpoint in service db just return
|
||||
if _, ok := sr[ep.Name()]; ok {
|
||||
n.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
sr[ep.Name()] = iface.Address().IP
|
||||
sr[ep.Name()+"."+n.name] = iface.Address().IP
|
||||
} else {
|
||||
|
@ -793,8 +808,12 @@ func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool
|
|||
}
|
||||
|
||||
var sbList []*sandbox
|
||||
for _, ep := range localEps {
|
||||
if sb, hasSandbox := ep.getSandbox(); hasSandbox {
|
||||
for _, lEp := range localEps {
|
||||
if ep.ID() == lEp.ID() {
|
||||
continue
|
||||
}
|
||||
|
||||
if sb, hasSandbox := lEp.getSandbox(); hasSandbox {
|
||||
sbList = append(sbList, sb)
|
||||
}
|
||||
}
|
||||
|
@ -808,7 +827,7 @@ func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool
|
|||
}
|
||||
}
|
||||
|
||||
func (n *network) getSvcRecords() []etchosts.Record {
|
||||
func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record {
|
||||
n.Lock()
|
||||
defer n.Unlock()
|
||||
|
||||
|
@ -816,6 +835,10 @@ func (n *network) getSvcRecords() []etchosts.Record {
|
|||
sr, _ := n.ctrlr.svcDb[n.id]
|
||||
|
||||
for h, ip := range sr {
|
||||
if ep != nil && strings.Split(h, ".")[0] == ep.Name() {
|
||||
continue
|
||||
}
|
||||
|
||||
recs = append(recs, etchosts.Record{
|
||||
Hosts: h,
|
||||
IP: ip.String(),
|
||||
|
|
|
@ -367,6 +367,11 @@ func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoi
|
|||
c.Lock()
|
||||
if len(nw.localEps) == 0 {
|
||||
close(nw.stopCh)
|
||||
|
||||
// This is the last container going away for the network. Destroy
|
||||
// this network's svc db entry
|
||||
delete(c.svcDb, ep.getNetwork().ID())
|
||||
|
||||
delete(nmap, ep.getNetwork().ID())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue