From 3025738377410a7a668c4bab835e0008048b56fb Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 13:28:08 +0000 Subject: [PATCH 1/9] Extract pluginNameFromAddress() function --- plugin/plugin.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index ddbc7327..91fb39d6 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -57,8 +57,7 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre if !isPluginV2 { Log.Println("Creating default 'weave' network") options := map[string]interface{}{MulticastOption: "true"} - // TODO: the driver name should be extracted from pluginMeshSocket - dockerClient.EnsureNetwork("weave", "weavemesh", defaultSubnet, options) + dockerClient.EnsureNetwork("weave", pluginNameFromAddress(meshAddress), defaultSubnet, options) } ready() @@ -70,7 +69,7 @@ func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address if isPluginV2 { name = pluginV2Name } else { - name = strings.TrimSuffix(path.Base(address), ".sock") + name = pluginNameFromAddress(address) } d, err := netplugin.New(dockerClient, weave, name, scope, dns, isPluginV2, forceMulticast) @@ -95,3 +94,8 @@ func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address return listener, nil } + +// Take a socket address like "/run/docker/plugins/weavemesh.sock" and extract the plugin name "weavemesh" +func pluginNameFromAddress(address string) string { + return strings.TrimSuffix(path.Base(address), ".sock") +} From b0da4f6b91c81c66e9f7bf6143de818b0aba7e5a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 14:01:05 +0000 Subject: [PATCH 2/9] Move proxy and plugin status from shell to Go In the process we stop printing out the `PLUGIN_FULL_NAME`, but that is assumed to be something the user can figure out from `docker plugin ls` --- plugin/status.go | 19 +++++++++++++++++++ prog/weaver/http.go | 23 +++++++++++++++++++++-- prog/weaver/main.go | 10 ++++++++-- proxy/status.go | 15 +++++++++++++++ weave | 14 -------------- 5 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 plugin/status.go create mode 100644 proxy/status.go diff --git a/plugin/status.go b/plugin/status.go new file mode 100644 index 00000000..fc44990b --- /dev/null +++ b/plugin/status.go @@ -0,0 +1,19 @@ +package plugin + +type Status struct { + DriverName string + MeshDriverName string `json:"MeshDriverName,omitempty"` + Version int +} + +func NewStatus(address, meshAddress string, isPluginV2 bool) *Status { + status := &Status{ + DriverName: pluginNameFromAddress(address), + MeshDriverName: pluginNameFromAddress(meshAddress), + Version: 1, + } + if isPluginV2 { + status.Version = 2 + } + return status +} diff --git a/prog/weaver/http.go b/prog/weaver/http.go index f18ac745..57197e13 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -17,6 +17,8 @@ import ( "github.com/weaveworks/weave/ipam" "github.com/weaveworks/weave/nameserver" "github.com/weaveworks/weave/net/address" + "github.com/weaveworks/weave/plugin" + "github.com/weaveworks/weave/proxy" weave "github.com/weaveworks/weave/router" ) @@ -203,6 +205,18 @@ var statusTemplate = defTemplate("status", `\ TTL: {{.DNS.TTL}} Entries: {{countDNSEntries .DNS.Entries}} {{end}}\ +{{if .Proxy}}\ + + Service: proxy + Address: {{printList .Proxy.Addresses}} +{{end}}\ +{{if .Plugin}}\ + + Service: plugin (v{{.Plugin.Version}}) +{{if eq .Plugin.Version 1}}\ + DriverName: {{.Plugin.DriverName}} +{{end}}\ +{{end}}\ `) var targetsTemplate = defTemplate("targetsTemplate", `\ @@ -280,10 +294,12 @@ type WeaveStatus struct { Router *weave.NetworkRouterStatus `json:"Router,omitempty"` IPAM *ipam.Status `json:"IPAM,omitempty"` DNS *nameserver.Status `json:"DNS,omitempty"` + Proxy *proxy.Status `json:"Proxy,omitempty"` + Plugin *plugin.Status `json:"Plugin,omitempty"` } // Read-only functions, suitable for exposing on an unprotected socket -func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, waitReady *common.WaitGroup) { +func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, prxy *proxy.Proxy, pluginStatus *plugin.Status, waitReady *common.WaitGroup) { status := func() WeaveStatus { return WeaveStatus{ waitReady.IsDone(), @@ -291,7 +307,10 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout versionCheck(), weave.NewNetworkRouterStatus(router), ipam.NewStatus(allocator, defaultSubnet), - nameserver.NewStatus(ns, dnsserver)} + nameserver.NewStatus(ns, dnsserver), + proxy.NewStatus(prxy), + pluginStatus, + } } muxRouter.Methods("GET").Path("/report").Headers("Accept", "application/json").HandlerFunc( func(w http.ResponseWriter, r *http.Request) { diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 7e7d5dcf..2a01c6f0 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -427,6 +427,12 @@ func main() { } checkFatal(router.CreateRestartSentinel()) + // Slightly ugly that plugin status is separated from the plugin.Start call + var pluginStatus *plugin.Status + if enablePlugin || enablePluginV2 { + pluginStatus = plugin.NewStatus(pluginSocket, pluginMeshSocket, enablePluginV2) + } + // The weave script always waits for a status call to succeed, // so there is no point in doing "weave launch --http-addr ''". // This is here to support stand-alone use of weaver. @@ -439,7 +445,7 @@ func main() { ns.HandleHTTP(muxRouter, dockerCli) } router.HandleHTTP(muxRouter) - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String()) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) if proxy != nil { @@ -452,7 +458,7 @@ func main() { if statusAddr != "" { muxRouter := mux.NewRouter() - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) statusMux := http.NewServeMux() statusMux.Handle("/", muxRouter) diff --git a/proxy/status.go b/proxy/status.go new file mode 100644 index 00000000..802ed88c --- /dev/null +++ b/proxy/status.go @@ -0,0 +1,15 @@ +package proxy + +type Status struct { + Addresses []string +} + +func NewStatus(proxy *Proxy) *Status { + if proxy == nil { + return nil + } + status := &Status{ + Addresses: proxy.normalisedAddrs, + } + return status +} diff --git a/weave b/weave index 6bdc4459..8e955fe9 100755 --- a/weave +++ b/weave @@ -1456,20 +1456,6 @@ case "$COMMAND" in echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2 usage fi - if [ -z "$SUB_STATUS" ] && PROXY_ADDRS=$(proxy_addrs 2>/dev/null) ; then - echo - echo " Service: proxy" - echo " Address: $PROXY_ADDRS" - fi - if [ -z "$SUB_STATUS" ] && is_plugin_v1_enabled ; then - echo - echo " Service: plugin (v1)" - echo " DriverName: weave" - elif [ -z "$SUB_STATUS" ] && PLUGIN_FULL_NAME=$(is_plugin_v2_enabled) ; then - echo - echo " Service: plugin (v2)" - echo " DriverName: $PLUGIN_FULL_NAME" - fi [ -n "$SUB_STATUS" ] || echo [ $res -eq 0 ] ;; From def9f2d4077024fe9cc0d579f555111ae75a2032 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 14:30:35 +0000 Subject: [PATCH 3/9] Check if weave is running for any reason before launching --- weave | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/weave b/weave index 8e955fe9..39382bfd 100755 --- a/weave +++ b/weave @@ -593,14 +593,6 @@ is_plugin_v2_enabled() { util_op is-docker-plugin-enabled $PLUGIN_NAME 2>/dev/null } -# Check that plugin (v2) is not running. -check_not_running_plugin_v2() { - if is_plugin_v2_enabled; then - echo "Docker plugin \"$PLUGIN_NAME\" is running; Aborting." >&2 - return 1 - fi -} - # Check that a container for component $1 named $2 with image $3 is not running check_not_running() { RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true @@ -1417,7 +1409,10 @@ case "$COMMAND" in launch) deprecation_warnings "$@" check_not_running router $CONTAINER_NAME $BASE_IMAGE - check_not_running_plugin_v2 + if http_call $HTTP_ADDR GET /status >/dev/null 2>&1 ; then + echo "Weave Net is already running" >&2 + exit 1 + fi # Plugin and proxy are started by default. Should users additionally pass --plugin=false or --proxy=false, their overrides will take precedence when parsed by Go. launch --plugin --proxy "$@" echo "$WEAVE_CONTAINER" From a36fc867d1d17b9b5da655e9b55213f7bae4d489 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 14:31:59 +0000 Subject: [PATCH 4/9] Formatting of status message --- prog/weaver/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prog/weaver/http.go b/prog/weaver/http.go index 57197e13..34564344 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -214,7 +214,7 @@ var statusTemplate = defTemplate("status", `\ Service: plugin (v{{.Plugin.Version}}) {{if eq .Plugin.Version 1}}\ - DriverName: {{.Plugin.DriverName}} + DriverName: {{.Plugin.DriverName}} {{end}}\ {{end}}\ `) From 292a50a891cdcea786ef728d90012a690f5881d9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 14:53:45 +0000 Subject: [PATCH 5/9] Don't check if the plugin is enabled before trying to remove the default 'weave network' If the plugin wasn't enabled then that network shouldn't exist. If the network 'weave' doesn't exist then util_op remove-plugin-network will do nothing. If it does exist for some reason then docker will pause for a while and remove it anyway. --- weave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave b/weave index 39382bfd..8a6b23c8 100755 --- a/weave +++ b/weave @@ -1303,7 +1303,7 @@ launch() { } stop() { - ! is_plugin_v1_enabled || util_op remove-plugin-network weave || true + util_op remove-plugin-network weave || true warn_if_stopping_proxy_in_env docker stop $CONTAINER_NAME >/dev/null 2>&1 || echo "Weave is not running." >&2 # In case user has upgraded from Date: Mon, 15 May 2017 14:59:47 +0000 Subject: [PATCH 6/9] Don't check if weave is running in protect_against_docker_hang Since it is only called in contexts where we have already checked that. We don't need the detail of whether plugin is enabled; if it's not running then it's ok to remove those socket files. --- weave | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/weave b/weave index 8a6b23c8..162e365f 100755 --- a/weave +++ b/weave @@ -582,17 +582,6 @@ attach() { # functions for interacting with containers ###################################################################### -# Docker Plugin V1 runs in a Docker container. -is_plugin_v1_enabled() { - docker inspect -f '{{.Config.Cmd}}' $CONTAINER_NAME 2>/dev/null | grep -q -- "--plugin" -} - -# The presence of Docker Plugin V2 can be checked only via 'docker plugin', -# as v2 plugins do not run as regular containers. -is_plugin_v2_enabled() { - util_op is-docker-plugin-enabled $PLUGIN_NAME 2>/dev/null -} - # Check that a container for component $1 named $2 with image $3 is not running check_not_running() { RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true @@ -1313,10 +1302,8 @@ stop() { } protect_against_docker_hang() { - # If the plugin is not running, remove its socket so Docker doesn't try to talk to it - if ! is_plugin_v1_enabled && ! is_plugin_v2_enabled ; then - rm -f $HOST_ROOT/run/docker/plugins/weave.sock $HOST_ROOT/run/docker/plugins/weavemesh.sock - fi + # Since the plugin is not running, remove its socket so Docker doesn't try to talk to it + rm -f $HOST_ROOT/run/docker/plugins/weave.sock $HOST_ROOT/run/docker/plugins/weavemesh.sock } ###################################################################### From 280651da9c08ed86471514eb8994100627660c18 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 May 2017 10:45:17 +0000 Subject: [PATCH 7/9] Create constant for 'weave' network name and move inside if-statement for weavemesh --- plugin/plugin.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index 91fb39d6..9021ebcf 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -18,6 +18,7 @@ import ( const ( pluginV2Name = "net-plugin" + defaultNetwork = "weave" MulticastOption = netplugin.MulticastOption ) @@ -53,11 +54,11 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre } defer os.Remove(meshAddress) defer meshListener.Close() - } - if !isPluginV2 { - Log.Println("Creating default 'weave' network") - options := map[string]interface{}{MulticastOption: "true"} - dockerClient.EnsureNetwork("weave", pluginNameFromAddress(meshAddress), defaultSubnet, options) + if !isPluginV2 { + Log.Printf("Creating default %q network", defaultNetwork) + options := map[string]interface{}{MulticastOption: "true"} + dockerClient.EnsureNetwork(defaultNetwork, pluginNameFromAddress(meshAddress), defaultSubnet, options) + } } ready() From 4f485f856b8abfbe4745434e0a01cfef2fe344d8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 May 2017 12:47:41 +0000 Subject: [PATCH 8/9] Factor out Plugin variables into Plugin and plugin.Config structs --- plugin/plugin.go | 44 ++++++++++++++++------ plugin/status.go | 11 ++++-- prog/weaver/http.go | 4 +- prog/weaver/main.go | 90 +++++++++++++++++++++------------------------ 4 files changed, 84 insertions(+), 65 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index 9021ebcf..c1890193 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -24,40 +24,62 @@ const ( var Log = common.Log -func Start(weaveAPIAddr string, dockerClient *docker.Client, address string, meshAddress string, dns bool, isPluginV2, forceMulticast bool, defaultSubnet string, ready func()) { +type Config struct { + Socket string + MeshSocket string + Enable bool + EnableV2 bool + EnableV2Multicast bool + DNS bool + DefaultSubnet string +} + +type Plugin struct { + Config +} + +func NewPlugin(config Config) *Plugin { + if !config.Enable && !config.EnableV2 { + return nil + } + plugin := &Plugin{Config: config} + return plugin +} + +func (plugin *Plugin) Start(weaveAPIAddr string, dockerClient *docker.Client, ready func()) { weave := weaveapi.NewClient(weaveAPIAddr, Log) Log.Info("Waiting for Weave API Server...") weave.WaitAPIServer(30) Log.Info("Finished waiting for Weave API Server") - if err := run(dockerClient, weave, address, meshAddress, dns, isPluginV2, forceMulticast, defaultSubnet, ready); err != nil { + if err := plugin.run(dockerClient, weave, ready); err != nil { Log.Fatal(err) } } -func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string, dns, isPluginV2, forceMulticast bool, defaultSubnet string, ready func()) error { +func (plugin *Plugin) run(dockerClient *docker.Client, weave *weaveapi.Client, ready func()) error { endChan := make(chan error, 1) - if address != "" { - globalListener, err := listenAndServe(dockerClient, weave, address, endChan, "global", false, dns, isPluginV2, forceMulticast) + if plugin.Socket != "" { + globalListener, err := listenAndServe(dockerClient, weave, plugin.Socket, endChan, "global", false, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast) if err != nil { return err } - defer os.Remove(address) + defer os.Remove(plugin.Socket) defer globalListener.Close() } - if meshAddress != "" { - meshListener, err := listenAndServe(dockerClient, weave, meshAddress, endChan, "local", true, dns, isPluginV2, forceMulticast) + if plugin.MeshSocket != "" { + meshListener, err := listenAndServe(dockerClient, weave, plugin.MeshSocket, endChan, "local", true, plugin.DNS, plugin.EnableV2, plugin.EnableV2Multicast) if err != nil { return err } - defer os.Remove(meshAddress) + defer os.Remove(plugin.MeshSocket) defer meshListener.Close() - if !isPluginV2 { + if !plugin.EnableV2 { Log.Printf("Creating default %q network", defaultNetwork) options := map[string]interface{}{MulticastOption: "true"} - dockerClient.EnsureNetwork(defaultNetwork, pluginNameFromAddress(meshAddress), defaultSubnet, options) + dockerClient.EnsureNetwork(defaultNetwork, pluginNameFromAddress(plugin.MeshSocket), plugin.DefaultSubnet, options) } } ready() diff --git a/plugin/status.go b/plugin/status.go index fc44990b..d22863a7 100644 --- a/plugin/status.go +++ b/plugin/status.go @@ -6,13 +6,16 @@ type Status struct { Version int } -func NewStatus(address, meshAddress string, isPluginV2 bool) *Status { +func (plugin *Plugin) NewStatus() *Status { + if plugin == nil { + return nil + } status := &Status{ - DriverName: pluginNameFromAddress(address), - MeshDriverName: pluginNameFromAddress(meshAddress), + DriverName: pluginNameFromAddress(plugin.Socket), + MeshDriverName: pluginNameFromAddress(plugin.MeshSocket), Version: 1, } - if isPluginV2 { + if plugin.EnableV2 { status.Version = 2 } return status diff --git a/prog/weaver/http.go b/prog/weaver/http.go index 34564344..2df37562 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -299,7 +299,7 @@ type WeaveStatus struct { } // Read-only functions, suitable for exposing on an unprotected socket -func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, prxy *proxy.Proxy, pluginStatus *plugin.Status, waitReady *common.WaitGroup) { +func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer, prxy *proxy.Proxy, plugin *plugin.Plugin, waitReady *common.WaitGroup) { status := func() WeaveStatus { return WeaveStatus{ waitReady.IsDone(), @@ -309,7 +309,7 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout ipam.NewStatus(allocator, defaultSubnet), nameserver.NewStatus(ns, dnsserver), proxy.NewStatus(prxy), - pluginStatus, + plugin.NewStatus(), } } muxRouter.Methods("GET").Path("/report").Headers("Accept", "application/json").HandlerFunc( diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 2a01c6f0..51f1df97 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -132,40 +132,36 @@ 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 = "info" - 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 = getenvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock") + justVersion bool + config mesh.Config + bridgeConfig weavenet.BridgeConfig + networkConfig weave.NetworkConfig + protocolMinVersion int + resume bool + routerName string + nickName string + password string + pktdebug bool + logLevel = "info" + 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 + pluginConfig plugin.Config + defaultDockerHost = getenvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock") ) mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit") @@ -211,11 +207,11 @@ func main() { mflag.StringVar(&token, []string{"-token"}, "", "token for peer discovery") mflag.StringVar(&advertiseAddress, []string{"-advertise-address"}, "", "address to advertise for peer discovery") - 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") + mflag.BoolVar(&pluginConfig.Enable, []string{"-plugin"}, false, "enable Docker plugin (v1)") + mflag.BoolVar(&pluginConfig.EnableV2, []string{"-plugin-v2"}, false, "enable Docker plugin (v2)") + mflag.BoolVar(&pluginConfig.EnableV2Multicast, []string{"-plugin-v2-multicast"}, false, "enable multicast for Docker plugin (v2)") + mflag.StringVar(&pluginConfig.Socket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen") + mflag.StringVar(&pluginConfig.MeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode") proxyConfig := configureProxy(version, defaultDockerHost) if bridgeConfig.AWSVPC { @@ -427,11 +423,9 @@ func main() { } checkFatal(router.CreateRestartSentinel()) - // Slightly ugly that plugin status is separated from the plugin.Start call - var pluginStatus *plugin.Status - if enablePlugin || enablePluginV2 { - pluginStatus = plugin.NewStatus(pluginSocket, pluginMeshSocket, enablePluginV2) - } + pluginConfig.DNS = !noDNS + pluginConfig.DefaultSubnet = defaultSubnet.String() + plugin := plugin.NewPlugin(pluginConfig) // The weave script always waits for a status call to succeed, // so there is no point in doing "weave launch --http-addr ''". @@ -445,7 +439,7 @@ func main() { ns.HandleHTTP(muxRouter, dockerCli) } router.HandleHTTP(muxRouter) - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, plugin, &waitReady) HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String()) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) if proxy != nil { @@ -458,7 +452,7 @@ func main() { if statusAddr != "" { muxRouter := mux.NewRouter() - HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, pluginStatus, &waitReady) + HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, plugin, &waitReady) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) statusMux := http.NewServeMux() statusMux.Handle("/", muxRouter) @@ -466,8 +460,8 @@ func main() { go listenAndServeHTTP(statusAddr, statusMux) } - if enablePlugin || enablePluginV2 { - go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket, !noDNS, enablePluginV2, enablePluginV2Multicast, defaultSubnet.String(), waitReady.Add()) + if plugin != nil { + go plugin.Start(httpAddr, dockerCli, waitReady.Add()) } if bridgeConfig.AWSVPC { From 933b395de482a00a73693b11381f2f5d49b4255b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 May 2017 12:57:23 +0000 Subject: [PATCH 9/9] Report plugin version status via the Config object --- plugin/status.go | 7 ++----- prog/weaver/http.go | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugin/status.go b/plugin/status.go index d22863a7..bdaf894c 100644 --- a/plugin/status.go +++ b/plugin/status.go @@ -1,9 +1,9 @@ package plugin type Status struct { + Config Config DriverName string MeshDriverName string `json:"MeshDriverName,omitempty"` - Version int } func (plugin *Plugin) NewStatus() *Status { @@ -13,10 +13,7 @@ func (plugin *Plugin) NewStatus() *Status { status := &Status{ DriverName: pluginNameFromAddress(plugin.Socket), MeshDriverName: pluginNameFromAddress(plugin.MeshSocket), - Version: 1, - } - if plugin.EnableV2 { - status.Version = 2 + Config: plugin.Config, } return status } diff --git a/prog/weaver/http.go b/prog/weaver/http.go index 2df37562..ce59a843 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -212,8 +212,10 @@ var statusTemplate = defTemplate("status", `\ {{end}}\ {{if .Plugin}}\ - Service: plugin (v{{.Plugin.Version}}) -{{if eq .Plugin.Version 1}}\ +{{if .Plugin.Config.EnableV2}}\ + Service: plugin (v2) +{{else}}\ + Service: plugin (legacy) DriverName: {{.Plugin.DriverName}} {{end}}\ {{end}}\