Unify weave and launch.sh CNI setup
Test 830 has to run CNI plugin under sudo now
This commit is contained in:
1 parent
882bff292e
commit
ec21afb426
3 files changed
+43
-74
No files matched your search
+11
-54
@@ -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 <<EOF
|
||||
{
|
||||
"name": "weave",
|
||||
"type": "weave-net"
|
||||
}
|
||||
EOF
|
||||
# Install CNI plugin binary to typical CNI bin location
|
||||
# with fall-back to CNI directory used by kube-up on GCI OS
|
||||
if mkdir -p /opt/cni/bin ; then
|
||||
export WEAVE_CNI_PLUGIN_DIR=/opt/cni/bin
|
||||
elif mkdir -p /host_home/kubernetes/bin ; then
|
||||
export WEAVE_CNI_PLUGIN_DIR=/host_home/kubernetes/bin
|
||||
else
|
||||
echo "Failed to install the Weave CNI plugin" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p /etc/cni/net.d
|
||||
/home/weave/weave --local setup-cni
|
||||
|
||||
wait $WEAVE_PID
|
||||
Reference in new issue
Block a user