diff --git a/prog/net-plugin/launch.sh b/prog/net-plugin/launch.sh index a39f7ced..7da70f89 100755 --- a/prog/net-plugin/launch.sh +++ b/prog/net-plugin/launch.sh @@ -23,28 +23,8 @@ echo "Starting launch.sh" # available to any plugin in general (https://github.com/moby/moby/issues/32815). PEERS= -IPALLOC_INIT= if [ ! -f "/restart.sentinel" ]; then - 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) - - if [ -z "$IPALLOC_INIT" ]; then - IPALLOC_INIT="observer" - if [ "$IS_SWARM_MANAGER" == "1" ]; then - IPALLOC_INIT="consensus=$(echo $SWARM_MANAGER_PEERS | wc -l)" - fi - fi - - PEERS=$(echo $SWARM_MANAGER_PEERS | tr '\n' ' ') - IPALLOC_INIT="--ipalloc-init $IPALLOC_INIT" + PEERS=$(/usr/bin/weaveutil swarm-manager-peers) fi router_bridge_opts() { @@ -63,7 +43,6 @@ exec /home/weave/weaver $EXTRA_ARGS --port=6783 $(router_bridge_opts) \ --http-addr=$HTTP_ADDR --status-addr=$STATUS_ADDR \ --no-dns \ --ipalloc-range=$IPALLOC_RANGE \ - $IPALLOC_INIT \ --nickname "$(hostname)" \ --log-level=debug \ --db-prefix="$WEAVE_DIR/weave" \ diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index aec68901..531009a5 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -39,7 +39,6 @@ func init() { "bridge-ip": bridgeIP, "unique-id": uniqueID, "swarm-manager-peers": swarmManagerPeers, - "is-swarm-manager": isSwarmManager, "is-docker-plugin-enabled": isDockerPluginEnabled, } } diff --git a/prog/weaveutil/swarm.go b/prog/weaveutil/swarm.go index 6131b3a9..e830ae35 100644 --- a/prog/weaveutil/swarm.go +++ b/prog/weaveutil/swarm.go @@ -2,48 +2,32 @@ package main import ( "fmt" - "os" "strings" - "github.com/docker/docker/api/types/swarm" "github.com/fsouza/go-dockerclient" "github.com/pkg/errors" ) const DOCKER_API_VERSION = "1.26" -func isSwarmManager(args []string) error { - info, err := dockerInfo() - if err != nil { - 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") - } - - return nil -} - func swarmManagerPeers(args []string) error { info, err := dockerInfo() if err != nil { return err } + ips := make([]string, 0) + for _, managerNode := range info.Swarm.RemoteManagers { ip, err := ipFromAddr(managerNode.Addr) if err != nil { return errors.Wrap(err, "ipFromAddr") } - fmt.Println(ip) + ips = append(ips, ip) } + fmt.Println(strings.Join(ips, " ")) + return nil }