From 09606db9c3646d7b5a675960dfb7694351448afc Mon Sep 17 00:00:00 2001 From: Martynas Pumputis Date: Fri, 7 Apr 2017 15:34:30 +0100 Subject: [PATCH] Exit when launching plugin-v2 if node is not active in Swarm We retrieve the list of swarm masters for peer discovery when launching plugin-v2, thus the node should belong to any Swarm when enabling the plugin. --- prog/net-plugin/launch.sh | 10 ++++++++-- prog/weaveutil/swarm.go | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/prog/net-plugin/launch.sh b/prog/net-plugin/launch.sh index 818f66f7..a372be13 100755 --- a/prog/net-plugin/launch.sh +++ b/prog/net-plugin/launch.sh @@ -16,10 +16,16 @@ echo "Starting launch.sh" # Check if the IP range overlaps anything existing on the host /usr/bin/weaveutil netcheck $IPALLOC_RANGE weave -# TODO(mp) add wait for swarm +STATUS=0 +/usr/bin/weaveutil is-swarm-manager 2>/dev/null || STATUS=$? +if [ $STATUS -eq 0 ]; then + IS_SWARM_MANAGER=1 +elif [ $STATUS -eq 20 ]; then + echo "Host swarm is not \"active\"; exiting." >&2 + exit 1 +fi SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers) -! /usr/bin/weaveutil is-swarm-manager || IS_SWARM_MANAGER=1 # Prevent from restoring from a persisted peers list rm -f "/restart.sentinel" diff --git a/prog/weaveutil/swarm.go b/prog/weaveutil/swarm.go index fbec29e9..6131b3a9 100644 --- a/prog/weaveutil/swarm.go +++ b/prog/weaveutil/swarm.go @@ -2,8 +2,10 @@ package main import ( "fmt" + "os" "strings" + "github.com/docker/docker/api/types/swarm" "github.com/fsouza/go-dockerclient" "github.com/pkg/errors" ) @@ -16,6 +18,11 @@ func isSwarmManager(args []string) error { return err } + // hack-y way to denote that a node does not belong to any swarm + if info.Swarm.LocalNodeState != swarm.LocalNodeStateActive { + os.Exit(20) + } + if !info.Swarm.ControlAvailable { return fmt.Errorf("node is not a manager") }