Merge pull request #2929 from weaveworks/issues/2906-plugin-v2-docker-sock
Work around missing docker.sock in plugin-v2
This commit is contained in:
commit
e89fc8f66a
7 files changed
+118
-106
No files matched your search
@@ -66,6 +66,14 @@
|
||||
"value"
|
||||
],
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"description": "Enable multicast for all Weave networks",
|
||||
"name": "WEAVE_MULTICAST",
|
||||
"settable": [
|
||||
"value"
|
||||
],
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"network": {
|
||||
|
||||
+15
-19
@@ -16,18 +16,16 @@ echo "Starting launch.sh"
|
||||
# Check if the IP range overlaps anything existing on the host
|
||||
/usr/bin/weaveutil netcheck $IPALLOC_RANGE weave
|
||||
|
||||
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
|
||||
# We need to get a list of Swarm nodes which might run the net-plugin:
|
||||
# - In the case of missing restart.sentinel, we assume that net-plugin has started
|
||||
# for the first time via the docker-plugin cmd. So it's safe to request docker.sock.
|
||||
# - If restart.sentinel present, let weaver restore from it as docker.sock is not
|
||||
# available to any plugin in general (https://github.com/moby/moby/issues/32815).
|
||||
|
||||
SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers)
|
||||
# Prevent from restoring from a persisted peers list
|
||||
rm -f "/restart.sentinel"
|
||||
PEERS=
|
||||
if [ ! -f "/restart.sentinel" ]; then
|
||||
PEERS=$(/usr/bin/weaveutil swarm-manager-peers)
|
||||
fi
|
||||
|
||||
router_bridge_opts() {
|
||||
echo --datapath=datapath
|
||||
@@ -35,12 +33,9 @@ router_bridge_opts() {
|
||||
[ -z "$WEAVE_NO_FASTDP" ] || echo --no-fastdp
|
||||
}
|
||||
|
||||
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
|
||||
multicast_opt() {
|
||||
[ -z "$WEAVE_MULTICAST" ] || echo "--plugin-v2-multicast"
|
||||
}
|
||||
|
||||
exec /home/weave/weaver $EXTRA_ARGS --port=6783 $(router_bridge_opts) \
|
||||
--host-root=/host \
|
||||
@@ -48,10 +43,11 @@ 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 $IPALLOC_INIT \
|
||||
--nickname "$(hostname)" \
|
||||
--log-level=debug \
|
||||
--db-prefix="$WEAVE_DIR/weave" \
|
||||
--plugin-v2 \
|
||||
$(multicast_opt) \
|
||||
--plugin-mesh-socket='' \
|
||||
$(echo $SWARM_MANAGER_PEERS | tr '\n' ' ')
|
||||
--docker-api='' \
|
||||
$PEERS
|
||||
+35
-33
@@ -123,38 +123,39 @@ func main() {
|
||||
runtime.GOMAXPROCS(procs)
|
||||
|
||||
var (
|
||||
justVersion bool
|
||||
config mesh.Config
|
||||
bridgeConfig weavenet.BridgeConfig
|
||||
networkConfig weave.NetworkConfig
|
||||
protocolMinVersion int
|
||||
resume bool
|
||||
routerName string
|
||||
nickName string
|
||||
password string
|
||||
pktdebug bool
|
||||
logLevel string
|
||||
prof string
|
||||
bufSzMB int
|
||||
noDiscovery bool
|
||||
httpAddr string
|
||||
statusAddr string
|
||||
ipamConfig ipamConfig
|
||||
dockerAPI string
|
||||
peers []string
|
||||
noDNS bool
|
||||
dnsConfig dnsConfig
|
||||
trustedSubnetStr string
|
||||
dbPrefix string
|
||||
hostRoot string
|
||||
procPath string
|
||||
discoveryEndpoint string
|
||||
token string
|
||||
advertiseAddress string
|
||||
pluginSocket string
|
||||
pluginMeshSocket string
|
||||
enablePlugin bool
|
||||
enablePluginV2 bool
|
||||
justVersion bool
|
||||
config mesh.Config
|
||||
bridgeConfig weavenet.BridgeConfig
|
||||
networkConfig weave.NetworkConfig
|
||||
protocolMinVersion int
|
||||
resume bool
|
||||
routerName string
|
||||
nickName string
|
||||
password string
|
||||
pktdebug bool
|
||||
logLevel string
|
||||
prof string
|
||||
bufSzMB int
|
||||
noDiscovery bool
|
||||
httpAddr string
|
||||
statusAddr string
|
||||
ipamConfig ipamConfig
|
||||
dockerAPI string
|
||||
peers []string
|
||||
noDNS bool
|
||||
dnsConfig dnsConfig
|
||||
trustedSubnetStr string
|
||||
dbPrefix string
|
||||
hostRoot string
|
||||
procPath string
|
||||
discoveryEndpoint string
|
||||
token string
|
||||
advertiseAddress string
|
||||
pluginSocket string
|
||||
pluginMeshSocket string
|
||||
enablePlugin bool
|
||||
enablePluginV2 bool
|
||||
enablePluginV2Multicast bool
|
||||
|
||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||
)
|
||||
@@ -208,6 +209,7 @@ func main() {
|
||||
|
||||
mflag.BoolVar(&enablePlugin, []string{"-plugin"}, false, "enable Docker plugin (v1)")
|
||||
mflag.BoolVar(&enablePluginV2, []string{"-plugin-v2"}, false, "enable Docker plugin (v2)")
|
||||
mflag.BoolVar(&enablePluginV2Multicast, []string{"-plugin-v2-multicast"}, false, "enable multicast for Docker plugin (v2)")
|
||||
mflag.StringVar(&pluginSocket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen")
|
||||
mflag.StringVar(&pluginMeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode")
|
||||
|
||||
@@ -427,7 +429,7 @@ func main() {
|
||||
}
|
||||
|
||||
if enablePlugin || enablePluginV2 {
|
||||
go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket, !noDNS, enablePluginV2)
|
||||
go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket, !noDNS, enablePluginV2, enablePluginV2Multicast)
|
||||
}
|
||||
if enablePlugin {
|
||||
Log.Println("Creating default 'weave' network")
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
+5
-21
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user