Merge pull request #2148 from weaveworks/issues/2146-cni-sock

Bind-mount the docker socket for CNI plugin

Fixes #2146
This commit is contained in:
Matthias Radestock committed 2016-04-11 16:03:14 +01:00
commit d1ca38e106
3 files changed
+41 -28

No files matched your search

+3
View File
@@ -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 == "" {
+21 -18
View File
@@ -4,34 +4,37 @@
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 <<EOF
{
"name": "weave",
"type": "weave-net"
}
EOF
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
cni_connect $HOST1 c2 >/dev/null
cni_connect $HOST1 c1 <<EOF
{
"name": "weave",
"type": "weave-net"
}
EOF
cni_connect $HOST1 c2 <<EOF
{
"name": "weave",
"type": "weave-net",
"ipam": {
"type": "weave-ipam",
"routes": [ { "dst": "10.32.0.0/12" } ]
}
}
EOF
C1IP=$(container_ip $HOST1 c1)
C2IP=$(container_ip $HOST1 c2)
+17 -10
View File
@@ -118,16 +118,16 @@ 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() {
cat >"$1" <<EOF
#!/bin/sh
docker run --rm --privileged --net=host --pid=host -i \\
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