From 499ade011685732728c9fd1ee2d7d5fe4a9a6a76 Mon Sep 17 00:00:00 2001 From: Tom Denham Date: Mon, 21 Sep 2015 11:13:14 -0700 Subject: [PATCH] Vendoring libnetwork Pull in version e5fea92a6c8a5968bdb8005bf959c6e23113b689 Fixes libnetwork regressions that stopped drivers that set routes from working. Pulls in libnetwork PRs #546 #543 Signed-off-by: Tom Denham --- hack/vendor.sh | 2 +- .../github.com/docker/libnetwork/.gitignore | 1 + .../src/github.com/docker/libnetwork/Makefile | 22 ++++++++++++++---- .../libnetwork/drivers/remote/driver.go | 4 ++-- .../docker/libnetwork/endpoint_info.go | 13 +---------- .../docker/libnetwork/osl/interface_linux.go | 8 +++++-- .../docker/libnetwork/osl/namespace_linux.go | 2 +- .../github.com/docker/libnetwork/sandbox.go | 3 ++- .../src/github.com/docker/libnetwork/store.go | 23 +++++++++++++++++-- 9 files changed, 52 insertions(+), 26 deletions(-) diff --git a/hack/vendor.sh b/hack/vendor.sh index 262fe58bba..ab09775f41 100755 --- a/hack/vendor.sh +++ b/hack/vendor.sh @@ -20,7 +20,7 @@ clone git github.com/tchap/go-patricia v2.1.0 clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git #get libnetwork packages -clone git github.com/docker/libnetwork 00a92f066e628e4c6d50979c070df377575aad18 +clone git github.com/docker/libnetwork e5fea92a6c8a5968bdb8005bf959c6e23113b689 clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4 diff --git a/vendor/src/github.com/docker/libnetwork/.gitignore b/vendor/src/github.com/docker/libnetwork/.gitignore index 0f3e6e30dd..0529bde798 100644 --- a/vendor/src/github.com/docker/libnetwork/.gitignore +++ b/vendor/src/github.com/docker/libnetwork/.gitignore @@ -23,6 +23,7 @@ _testmain.go *.exe *.test *.prof +cmd/dnet/dnet # Coverage *.tmp diff --git a/vendor/src/github.com/docker/libnetwork/Makefile b/vendor/src/github.com/docker/libnetwork/Makefile index fa5a4fe1ab..15ece669f9 100644 --- a/vendor/src/github.com/docker/libnetwork/Makefile +++ b/vendor/src/github.com/docker/libnetwork/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all-local build build-local check check-code check-format run-tests check-local integration-tests install-deps coveralls circle-ci +.PHONY: all all-local build build-local check check-code check-format run-tests check-local integration-tests install-deps coveralls circle-ci start-services clean SHELL=/bin/bash build_image=libnetwork-build dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork @@ -7,9 +7,9 @@ docker = docker run --rm -it ${dockerargs} ${container_env} ${build_image} ciargs = -e "COVERALLS_TOKEN=$$COVERALLS_TOKEN" -e "INSIDECONTAINER=-incontainer=true" cidocker = docker run ${ciargs} ${dockerargs} golang:1.4 -all: ${build_image}.created build check integration-tests +all: ${build_image}.created build check integration-tests clean -integration-tests: +integration-tests: ./cmd/dnet/dnet @if [ ! -d ./integration-tmp ]; then \ mkdir -p ./integration-tmp; \ git clone https://github.com/sstephenson/bats.git ./integration-tmp/bats; \ @@ -17,6 +17,15 @@ integration-tests: fi @./integration-tmp/bin/bats ./test/integration/dnet +./cmd/dnet/dnet: + make build-local + +clean: + @if [ -e ./cmd/dnet/dnet ]; then \ + echo "Removing dnet binary"; \ + rm -rf ./cmd/dnet/dnet; \ + fi + all-local: check-local build-local ${build_image}.created: @@ -67,10 +76,10 @@ run-tests: done @echo "Done running tests" -check-local: check-format check-code run-tests +check-local: check-format check-code start-services run-tests install-deps: - apt-get update && apt-get -y install iptables + apt-get update && apt-get -y install iptables zookeeperd git clone https://github.com/golang/tools /go/src/golang.org/x/tools go install golang.org/x/tools/cmd/vet go install golang.org/x/tools/cmd/goimports @@ -88,3 +97,6 @@ coveralls: circle-ci: @${cidocker} make install-deps build-local check-local coveralls make integration-tests + +start-services: + service zookeeper start diff --git a/vendor/src/github.com/docker/libnetwork/drivers/remote/driver.go b/vendor/src/github.com/docker/libnetwork/drivers/remote/driver.go index 4d1a134f09..cc1d41441e 100644 --- a/vendor/src/github.com/docker/libnetwork/drivers/remote/driver.go +++ b/vendor/src/github.com/docker/libnetwork/drivers/remote/driver.go @@ -192,8 +192,8 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, } ifaceName := res.InterfaceName - if ifaceName == nil { - return fmt.Errorf("no interface name information received") + if jinfo.InterfaceName() != nil && ifaceName == nil { + return fmt.Errorf("no interface name information received while one is expected") } if iface := jinfo.InterfaceName(); iface != nil { diff --git a/vendor/src/github.com/docker/libnetwork/endpoint_info.go b/vendor/src/github.com/docker/libnetwork/endpoint_info.go index ffc4787318..6d06675ae9 100644 --- a/vendor/src/github.com/docker/libnetwork/endpoint_info.go +++ b/vendor/src/github.com/docker/libnetwork/endpoint_info.go @@ -203,22 +203,11 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHo ep.joinInfo.StaticRoutes = append(ep.joinInfo.StaticRoutes, &r) } else { // If the route doesn't specify a next-hop, it must be a connected route, bound to an interface. - if err := ep.addInterfaceRoute(&r); err != nil { - return err - } + ep.iface.routes = append(ep.iface.routes, r.Destination) } return nil } -func (ep *endpoint) addInterfaceRoute(route *types.StaticRoute) error { - ep.Lock() - defer ep.Unlock() - - iface := ep.iface - iface.routes = append(iface.routes, route.Destination) - return nil -} - func (ep *endpoint) Sandbox() Sandbox { cnt, ok := ep.getSandbox() if !ok { diff --git a/vendor/src/github.com/docker/libnetwork/osl/interface_linux.go b/vendor/src/github.com/docker/libnetwork/osl/interface_linux.go index c314b011dc..0b0b0d9fa7 100644 --- a/vendor/src/github.com/docker/libnetwork/osl/interface_linux.go +++ b/vendor/src/github.com/docker/libnetwork/osl/interface_linux.go @@ -271,6 +271,11 @@ func (n *networkNamespace) AddInterface(srcName, dstPrefix string, options ...If return fmt.Errorf("failed to set link up: %v", err) } + // Set the routes on the interface. This can only be done when the interface is up. + if err := setInterfaceRoutes(iface, i); err != nil { + return fmt.Errorf("error setting interface %q routes to %q: %v", iface.Attrs().Name, i.Routes(), err) + } + n.Lock() n.iFaces = append(n.iFaces, i) n.Unlock() @@ -288,7 +293,6 @@ func configureInterface(iface netlink.Link, i *nwIface) error { {setInterfaceName, fmt.Sprintf("error renaming interface %q to %q", ifaceName, i.DstName())}, {setInterfaceIP, fmt.Sprintf("error setting interface %q IP to %q", ifaceName, i.Address())}, {setInterfaceIPv6, fmt.Sprintf("error setting interface %q IPv6 to %q", ifaceName, i.AddressIPv6())}, - {setInterfaceRoutes, fmt.Sprintf("error setting interface %q routes to %q", ifaceName, i.Routes())}, {setInterfaceMaster, fmt.Sprintf("error setting interface %q master to %q", ifaceName, i.DstMaster())}, } @@ -346,7 +350,7 @@ func setInterfaceRoutes(iface netlink.Link, i *nwIface) error { // In older kernels (like the one in Centos 6.6 distro) sysctl does not have netns support. Therefore // we cannot gather the statistics from /sys/class/net//statistics/ files. Per-netns stats -// are naturally found in /proc/net/dev in kernels which support netns (ifconfig relyes on that). +// are naturally found in /proc/net/dev in kernels which support netns (ifconfig relies on that). const ( netStatsFile = "/proc/net/dev" base = "[ ]*%s:([ ]+[0-9]+){16}" diff --git a/vendor/src/github.com/docker/libnetwork/osl/namespace_linux.go b/vendor/src/github.com/docker/libnetwork/osl/namespace_linux.go index 9b2c82eda6..1b7b230380 100644 --- a/vendor/src/github.com/docker/libnetwork/osl/namespace_linux.go +++ b/vendor/src/github.com/docker/libnetwork/osl/namespace_linux.go @@ -49,7 +49,7 @@ func init() { } func createBasePath() { - err := os.MkdirAll(prefix, 0644) + err := os.MkdirAll(prefix, 0755) if err != nil { panic("Could not create net namespace path directory") } diff --git a/vendor/src/github.com/docker/libnetwork/sandbox.go b/vendor/src/github.com/docker/libnetwork/sandbox.go index bd473947aa..e0a3b2e5b0 100644 --- a/vendor/src/github.com/docker/libnetwork/sandbox.go +++ b/vendor/src/github.com/docker/libnetwork/sandbox.go @@ -416,6 +416,7 @@ func (sb *sandbox) clearNetworkResources(ep *endpoint) error { const ( defaultPrefix = "/var/lib/docker/network/files" + dirPerm = 0755 filePerm = 0644 ) @@ -777,7 +778,7 @@ func (eh *epHeap) Pop() interface{} { } func createBasePath(dir string) error { - return os.MkdirAll(dir, filePerm) + return os.MkdirAll(dir, dirPerm) } func createFile(path string) error { diff --git a/vendor/src/github.com/docker/libnetwork/store.go b/vendor/src/github.com/docker/libnetwork/store.go index e14aa72b01..42a14de332 100644 --- a/vendor/src/github.com/docker/libnetwork/store.go +++ b/vendor/src/github.com/docker/libnetwork/store.go @@ -174,7 +174,11 @@ func (c *controller) watchNetworks() error { cs := c.store c.Unlock() - nwPairs, err := cs.KVStore().WatchTree(datastore.Key(datastore.NetworkKeyPrefix), nil) + networkKey := datastore.Key(datastore.NetworkKeyPrefix) + if err := ensureKeys(networkKey, cs); err != nil { + return fmt.Errorf("failed to ensure if the network keys are valid and present in store: %v", err) + } + nwPairs, err := cs.KVStore().WatchTree(networkKey, nil) if err != nil { return err } @@ -228,7 +232,11 @@ func (n *network) watchEndpoints() error { stopCh := n.stopWatchCh n.Unlock() - epPairs, err := cs.KVStore().WatchTree(datastore.Key(tmp.KeyPrefix()...), stopCh) + endpointKey := datastore.Key(tmp.KeyPrefix()...) + if err := ensureKeys(endpointKey, cs); err != nil { + return fmt.Errorf("failed to ensure if the endpoint keys are valid and present in store: %v", err) + } + epPairs, err := cs.KVStore().WatchTree(endpointKey, stopCh) if err != nil { return err } @@ -362,3 +370,14 @@ func (c *controller) processEndpointUpdate(ep *endpoint) bool { return false } + +func ensureKeys(key string, cs datastore.DataStore) error { + exists, err := cs.KVStore().Exists(key) + if err != nil { + return err + } + if exists { + return nil + } + return cs.KVStore().Put(key, []byte{}, nil) +}