CNI plugin implemented as script that docker runs plugin container,

installed via `weave setup`
This commit is contained in:
Bryan Boreham committed 2016-03-17 14:29:33 +00:00
1 parent ecdd7aa7ce
commit 024eb46c7d
2 files changed
+37 -2

No files matched your search

+5 -2
View File
@@ -26,6 +26,7 @@ var version = "(unreleased version)"
func main() {
var (
justVersion bool
cniNet, cniIpam bool
address string
meshAddress string
logLevel string
@@ -33,6 +34,8 @@ func main() {
)
flag.BoolVar(&justVersion, "version", false, "print version and exit")
flag.BoolVar(&cniNet, "cni-net", false, "act as a CNI network plugin")
flag.BoolVar(&cniIpam, "cni-ipam", false, "act as a CNI IPAM plugin")
flag.StringVar(&logLevel, "log-level", "info", "logging level (debug, info, warning, error)")
flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode")
@@ -50,11 +53,11 @@ func main() {
weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log)
switch {
case strings.HasSuffix(os.Args[0], "weave-ipam"):
case cniIpam || strings.HasSuffix(os.Args[0], "weave-ipam"):
i := ipamplugin.NewIpam(weave)
cni.PluginMain(i.CmdAdd, i.CmdDel)
os.Exit(0)
case strings.HasSuffix(os.Args[0], "weave"):
case cniNet || strings.HasSuffix(os.Args[0], "weave-net"):
n := netplugin.NewCNIPlugin(weave)
cni.PluginMain(n.CmdAdd, n.CmdDel)
os.Exit(0)
+32
View File
@@ -115,10 +115,35 @@ docker_run_options() {
echo --privileged --net=host $(docker_sock_options)
}
docker_exec_cni_options() {
[ "$1" = "setup" ] && 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 \\
-e CNI_VERSION -e CNI_COMMAND -e CNI_CONTAINERID -e CNI_NETNS \\
-e CNI_IFNAME -e CNI_ARGS -e CNI_PATH \\
$PLUGIN_IMAGE "$2"
EOF
chmod a+x "$1"
}
create_cni_config() {
cat >"$1" <<EOF
{
"name": "weave",
"type": "weave-net"
}
EOF
}
exec_remote() {
docker $DOCKER_CLIENT_ARGS run --rm \
$(docker_run_options) \
--pid=host \
$(docker_exec_cni_options "$@") \
-e DOCKERHUB_USER="$DOCKERHUB_USER" \
-e WEAVE_VERSION \
-e WEAVE_DEBUG \
@@ -1836,6 +1861,13 @@ 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
;;
version)
[ $# -eq 0 ] || usage