From e88e67f02c21d1ed9bde887ca2e80034d8a267a7 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 8 Apr 2016 15:16:54 +0100 Subject: [PATCH 1/5] Bind-mount docker socket for CNI plugin scripts --- weave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave b/weave index 7e725524..17eab19b 100755 --- a/weave +++ b/weave @@ -124,7 +124,7 @@ cni_volume_options() { create_cni_script() { cat >"$1" < Date: Fri, 8 Apr 2016 15:18:08 +0100 Subject: [PATCH 2/5] Sanity-check ipam args to make diagnosis easier --- plugin/ipam/cni.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/ipam/cni.go b/plugin/ipam/cni.go index a5d407b8..4c9a45a8 100644 --- a/plugin/ipam/cni.go +++ b/plugin/ipam/cni.go @@ -27,6 +27,9 @@ func (i *Ipam) Allocate(args *skel.CmdArgs) (*types.Result, error) { conf = &ipamConf{} } containerID := args.ContainerID + if containerID == "" { + return nil, fmt.Errorf("Weave CNI Allocate: blank container name") + } var ipnet *net.IPNet if conf.Subnet == "" { From 737b0e0504fa6f4ef055e4a40ee3b9347de380d9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 8 Apr 2016 17:59:23 +0100 Subject: [PATCH 3/5] Two different configs; ensure weave-ipam driver works when named --- test/830_cni_plugin_test.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/830_cni_plugin_test.sh b/test/830_cni_plugin_test.sh index 4631d97b..3b2df0e4 100755 --- a/test/830_cni_plugin_test.sh +++ b/test/830_cni_plugin_test.sh @@ -16,12 +16,7 @@ cni_connect() { docker_on $1 run --rm --privileged --net=host --pid=host -i \ -e CNI_VERSION=1 -e CNI_COMMAND=ADD -e CNI_CONTAINERID=c1 \ -e CNI_NETNS=/proc/$pid/ns/net -e CNI_IFNAME=eth0 -e CNI_PATH=/opt/cni/bin \ - weaveworks/plugin:latest $(coverage_args) --cni-net </dev/null -cni_connect $HOST1 c2 >/dev/null +cni_connect $HOST1 c1 >/dev/null </dev/null < Date: Mon, 11 Apr 2016 15:28:11 +0100 Subject: [PATCH 4/5] Extract out CNI setup so we can call it from a test --- weave | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/weave b/weave index 17eab19b..709f589a 100755 --- a/weave +++ b/weave @@ -118,7 +118,7 @@ docker_run_options() { } cni_volume_options() { - [ "$1" = "setup" ] && echo -v /etc/cni:/etc/cni -v /opt/cni:/opt/cni + [ "$1" = "setup" -o "$1" = "setup-cni" ] && echo -v /etc/cni:/etc/cni -v /opt/cni:/opt/cni } create_cni_script() { @@ -127,7 +127,7 @@ create_cni_script() { docker run --rm $(docker_run_options) --pid=host -i \\ -e CNI_VERSION -e CNI_COMMAND -e CNI_CONTAINERID -e CNI_NETNS \\ -e CNI_IFNAME -e CNI_ARGS -e CNI_PATH $(cni_volume_options setup) \\ - $PLUGIN_IMAGE "$2" + $PLUGIN_IMAGE $COVERAGE_ARGS $2 EOF chmod a+x "$1" } @@ -141,6 +141,16 @@ create_cni_config() { EOF } +setup_cni() { + if [ -d /opt/cni/bin ] ; then + create_cni_script /opt/cni/bin/weave-net --cni-net + create_cni_script /opt/cni/bin/weave-ipam --cni-ipam + fi + if [ -d /etc/cni/net.d -a ! -f /etc/cni/net.d/10-weave.conf ] ; then + create_cni_config /etc/cni/net.d/10-weave.conf + fi +} + exec_remote() { docker $DOCKER_CLIENT_ARGS run --rm \ $(docker_run_options) \ @@ -1880,13 +1890,10 @@ case "$COMMAND" in for img in $IMAGE $EXEC_IMAGE $PLUGIN_IMAGE ; do docker pull $img done - if [ -d /opt/cni/bin ] ; then - create_cni_script /opt/cni/bin/weave-net --cni-net - create_cni_script /opt/cni/bin/weave-ipam --cni-ipam - fi - if [ -d /etc/cni/net.d -a ! -f /etc/cni/net.d/10-weave.conf ] ; then - create_cni_config /etc/cni/net.d/10-weave.conf - fi + setup_cni + ;; + setup-cni) + setup_cni ;; version) [ $# -eq 0 ] || usage From 15bdf6cd2d640c8a8abc8097d9641dcdb34e5181 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 11 Apr 2016 15:28:53 +0100 Subject: [PATCH 5/5] Rework CNI test so it uses the scriptlet --- test/830_cni_plugin_test.sh | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/830_cni_plugin_test.sh b/test/830_cni_plugin_test.sh index 3b2df0e4..07aa6cf6 100755 --- a/test/830_cni_plugin_test.sh +++ b/test/830_cni_plugin_test.sh @@ -4,37 +4,31 @@ start_suite "Test CNI plugin" -coverage_args() { - # no coverage reporting for now; but when the plugin binary has - # been built for coverage reporting we need to prevent it from - # complaining about the non-coverage args. - [ -n "$COVERAGE" ] && echo "--" -} - cni_connect() { pid=$(container_pid $1 $2) - docker_on $1 run --rm --privileged --net=host --pid=host -i \ - -e CNI_VERSION=1 -e CNI_COMMAND=ADD -e CNI_CONTAINERID=c1 \ - -e CNI_NETNS=/proc/$pid/ns/net -e CNI_IFNAME=eth0 -e CNI_PATH=/opt/cni/bin \ - weaveworks/plugin:latest $(coverage_args) --cni-net + run_on $1 CNI_VERSION=1 CNI_COMMAND=ADD CNI_CONTAINERID=c1 CNI_IFNAME=eth0 \ + CNI_NETNS=/proc/$pid/ns/net CNI_PATH=/opt/cni/bin /opt/cni/bin/weave-net } +run_on $HOST1 sudo mkdir -p /opt/cni/bin +# setup-cni is a subset of 'weave setup', without doing any 'docker pull's +weave_on $HOST1 setup-cni weave_on $HOST1 launch weave_on $HOST1 expose C1=$(docker_on $HOST1 run --net=none --name=c1 -dt $SMALL_IMAGE /bin/sh) C2=$(docker_on $HOST1 run --net=none --name=c2 -dt $SMALL_IMAGE /bin/sh) -cni_connect $HOST1 c1 >/dev/null </dev/null <