diff --git a/prog/weave-kube/launch.sh b/prog/weave-kube/launch.sh index 11ab7134..2b4eff00 100755 --- a/prog/weave-kube/launch.sh +++ b/prog/weave-kube/launch.sh @@ -22,51 +22,6 @@ else fi fi -SOURCE_BINARY=/usr/bin/weaveutil -VERSION=$(/home/weave/weaver $EXTRA_ARGS --version | sed -e 's/weave router //') -PLUGIN="weave-plugin-$VERSION" - -install_cni_plugin() { - mkdir -p $1 || return 1 - if [ ! -f "$1/$PLUGIN" ]; then - cp "$SOURCE_BINARY" "$1/$PLUGIN" - fi -} - -upgrade_cni_plugin_symlink() { - # Remove potential temporary symlink from previous failed upgrade: - rm -f $1/$2.tmp - # Atomically create a symlink to the plugin: - ln -s "$1/$PLUGIN" $1/$2.tmp && mv -f $1/$2.tmp $1/$2 -} - -upgrade_cni_plugin() { - # Check if weave-net and weave-ipam are (legacy) copies of the plugin, and - # if so remove these so symlinks can be used instead from now onwards. - if [ -f $1/weave-net -a ! -L $1/weave-net ]; then rm $1/weave-net; fi - if [ -f $1/weave-ipam -a ! -L $1/weave-ipam ]; then rm $1/weave-ipam; fi - - # Create two symlinks to the plugin, as it has a different - # behaviour depending on its name: - if [ "$(readlink -f $1/weave-net)" != "$1/$PLUGIN" ]; then - upgrade_cni_plugin_symlink $1 weave-net - fi - if [ "$(readlink -f $1/weave-ipam)" != "$1/$PLUGIN" ]; then - upgrade_cni_plugin_symlink $1 weave-ipam - fi -} - -# Install CNI plugin binary to typical CNI bin location -# with fall-back to CNI directory used by kube-up on GCI OS. -if install_cni_plugin /opt/cni/bin ; then - upgrade_cni_plugin /opt/cni/bin -elif install_cni_plugin /host_home/kubernetes/bin ; then - upgrade_cni_plugin /host_home/kubernetes/bin -else - echo "Failed to install the Weave CNI plugin" >&2 - exit 1 -fi - # Need to create bridge before running weaver so we can use the peer address # (because of https://github.com/weaveworks/weave/issues/2480) WEAVE_NPC_OPTS="--expect-npc" @@ -145,15 +100,17 @@ done reclaim_ips "_" $IPS done -# Create CNI config, if not already there -if [ ! -f /etc/cni/net.d/10-weave.conf ] ; then - mkdir -p /etc/cni/net.d - cat > /etc/cni/net.d/10-weave.conf <&2 + exit 1 fi +mkdir -p /etc/cni/net.d +/home/weave/weave --local setup-cni wait $WEAVE_PID diff --git a/test/830_cni_plugin_test.sh b/test/830_cni_plugin_test.sh index b75c97eb..c574803c 100755 --- a/test/830_cni_plugin_test.sh +++ b/test/830_cni_plugin_test.sh @@ -7,7 +7,7 @@ start_suite "Test CNI plugin" cni_connect() { pid=$(container_pid $1 $2) id=$(docker_on $1 inspect -f '{{.Id}}' $2) - run_on $1 CNI_VERSION=1 CNI_COMMAND=ADD CNI_CONTAINERID=$id CNI_IFNAME=eth0 \ + run_on $1 sudo CNI_VERSION=1 CNI_COMMAND=ADD CNI_CONTAINERID=$id CNI_IFNAME=eth0 \ CNI_NETNS=/proc/$pid/ns/net CNI_PATH=/opt/cni/bin /opt/cni/bin/weave-net } diff --git a/weave b/weave index a21e12fa..37fb4ef2 100755 --- a/weave +++ b/weave @@ -337,6 +337,8 @@ CONTAINER_NAME=${WEAVE_CONTAINER_NAME:-weave} BASE_PLUGIN_IMAGE=$DOCKERHUB_USER/plugin PLUGIN_IMAGE=$BASE_PLUGIN_IMAGE:$IMAGE_VERSION PLUGIN_CONTAINER_NAME=weaveplugin +CNI_PLUGIN_NAME="weave-plugin-$IMAGE_VERSION" +CNI_PLUGIN_DIR=${WEAVE_CNI_PLUGIN_DIR:-$HOST_ROOT/opt/cni/bin} # Note VOLUMES_CONTAINER which is for weavewait should change when you upgrade Weave VOLUMES_CONTAINER_NAME=weavevolumes-$IMAGE_VERSION # DB files should remain when you upgrade, so version number not included in name @@ -1041,23 +1043,34 @@ peer_args() { # CNI helpers ###################################################################### -create_cni_script() { - # If target file is a symlink, it's probably a remnant of a weave-kube - # installation - if the user has now switched back to `weave launch`, - # we need to remove the link before rewriting the contents: - [ -L "$1" ] && rm "$1" # fail if we can't remove the link +install_cni_plugin() { + mkdir -p $1 || return 1 + if [ ! -f "$1/$CNI_PLUGIN_NAME" ]; then + cp /usr/bin/weaveutil "$1/$CNI_PLUGIN_NAME" + fi +} - cat >"$1" <