From 90907a76472b13c1fbd053ab4fe124fd822c0eba Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Mon, 30 Jul 2018 16:45:45 +0530 Subject: [PATCH] Fix to use 10-weave.conflist instead of 10-weave.conf as CNI config file. Also adds support for portmap as additional plugin along with weave-net Fixes #3016 --- docs/entrypoints.md | 8 ++++---- site/kubernetes.md | 4 +++- test/config.sh | 2 +- weave | 24 ++++++++++++++++++++---- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/docs/entrypoints.md b/docs/entrypoints.md index e04ecae1..9dab85f9 100644 --- a/docs/entrypoints.md +++ b/docs/entrypoints.md @@ -35,21 +35,21 @@ weave-kube is an image with the weave binaries and a wrapper script installed. I 1. Setting up the weave network 2. Connecting to peers -3. Copy the weave CNI-compatible binary plugin `weaveutil` to `/opt/cni/bin/weave-net` and weave config in `/etc/cni/net.d/10-weave.conf` +3. Copy the weave CNI-compatible binary plugin `weaveutil` to `/opt/cni/bin/weave-net` and weave config in `/etc/cni/net.d/10-weave.conflist` 4. Running the weave network policy controller (weave-npc) to implement kubernetes' `NetworkPolicy` Once installation is complete, each network-relevant change in a container leads `kubelet` to: 1. Set certain environment variables to configure the CNI plugin, mostly related to the container ID 2. Launch `/opt/cni/bin/weave-net` -3. Pass the CNI config - the contents of `/etc/cni/net.d/10-weave.conf` to `weave-net` +3. Pass the CNI config - the contents of `/etc/cni/net.d/10-weave.conflist` to `weave-net` Thus, when each container is changed, and `kubelet` calls weave as a CNI plugin, it really just is launching `weaveutil` as `weave-net`. The installation and setup of all of the above - and therefore the entrypoint to the weave-kube image - is the script `prog/weave-kube/launch.sh`. `launch.sh` does the following: 1. Read configuration variables from the environment. When the documentation for `weave-kube` describes configuring the weave network by changing the environment variables in the daemonset in the `.yml` file, `launch.sh` reads these environment variables. -2. Set up the config file at `/etc/cni/net.d/10-weave.conf` +2. Set up the config file at `/etc/cni/net.d/10-weave.conflist` 3. Run the `weave` initialization script 4. Run `weaver` with the correct configuration passed as command-line options @@ -66,5 +66,5 @@ To add new options to how weave should run with each invocation, you would do th * have `prog/weave-kube/launch.sh` read it as an environment variable and set inside * set a default for the environment variable in `prog/weave-kube/weave-daemonset-k8s-1.6.yaml` and `weave-daemonset.yaml` * if it should be set via `weaver` globally on its one-time initialization invocation, pass it on in `launch.sh` - * if it needs to be set via `weaveutil` on each invocation of `weave-net`, have `launch.sh` save it as an option in the CNI config file `/etc/cni/net.d/10-weave.conf` and then have the CNI code in `plugin/net/cni.go` in `weaveutil` read it and use where appropriate + * if it needs to be set via `weaveutil` on each invocation of `weave-net`, have `launch.sh` save it as an option in the CNI config file `/etc/cni/net.d/10-weave.conflist` and then have the CNI code in `plugin/net/cni.go` in `weaveutil` read it and use where appropriate 7. Document it! diff --git a/site/kubernetes.md b/site/kubernetes.md index 0c8b13f8..f713d174 100644 --- a/site/kubernetes.md +++ b/site/kubernetes.md @@ -30,6 +30,8 @@ Then run: weave setup +Weave net depends on the *portmap* [standard](https://github.com/containernetworking/plugins) CNI plugin to support *hostport* functionality. Please ensure that *portmap* CNI plugin is installed in `/opt/cni/bin` directory. + #### Launching Weave Net To create a network that spans multiple hosts, the Weave peers must be connected to each other. @@ -45,7 +47,7 @@ for a discussion on peer connections. All CNI plugins are configured by a JSON file in the directory `/etc/cni/net.d/`. `weave setup` installs a minimal configuration -file named `10-weave.conf`, which you can alter to suit your needs. +file named `10-weave.conflist`, which you can alter to suit your needs. See the [CNI Spec](https://github.com/appc/cni/blob/master/SPEC.md#network-configuration) for details on the format and contents of this file. diff --git a/test/config.sh b/test/config.sh index 16d252cc..29958867 100644 --- a/test/config.sh +++ b/test/config.sh @@ -329,7 +329,7 @@ start_suite() { [ -z "$DEBUG" ] || echo "Cleaning up on $host: removing all containers and resetting weave" rm_containers $host $(docker_on $host ps -aq 2>/dev/null) weave_on $host reset 2>/dev/null - run_on $host sudo rm -f /opt/cni/bin/weave-plugin-latest /opt/cni/bin/weave-net /opt/cni/bin/weave-ipam /etc/cni/net.d/10-weave.conf + run_on $host sudo rm -f /opt/cni/bin/weave-plugin-latest /opt/cni/bin/weave-net /opt/cni/bin/weave-ipam /etc/cni/net.d/10-weave.conflist done whitely echo "$@" } diff --git a/weave b/weave index ad7d4167..bf46b3cf 100755 --- a/weave +++ b/weave @@ -729,9 +729,20 @@ upgrade_cni_plugin() { create_cni_config() { cat >"$1" < 2.4.0. So in case of upgrade of old + # clusters with Weave version <= 2.4.0 remove existing 10-weave.conf + rm -f $HOST_ROOT/etc/cni/net.d/10-weave.conf + + if [ -d $HOST_ROOT/etc/cni/net.d -a ! -f $HOST_ROOT/etc/cni/net.d/10-weave.conflist ] ; then + create_cni_config $HOST_ROOT/etc/cni/net.d/10-weave.conflist $HAIRPIN_MODE fi }