Extract out CNI setup so we can call it from a test

This commit is contained in:
Bryan Boreham committed 2016-04-11 15:28:11 +01:00
1 parent 737b0e0504
commit 4bd6de5995
1 file changed
+16 -9
+16 -9
View File
@@ -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