From 5cf973f03aa80939af5b465d71c026d1e938a841 Mon Sep 17 00:00:00 2001 From: Marc CARRE Date: Tue, 9 May 2017 17:28:18 +0100 Subject: [PATCH] Add --proxy option to enable/disable proxy. Weave Net initially had the ability to start a single component at a time with `launch-proxy` and `launch-router`. This change enables this again via `--proxy=false` despite the merge of the proxy and the router. Note that by default: - `launch` passes `--proxy` which enables the proxy and keeps behaviour consistent with `launch` pre-merge, - `weaver` defaults `--proxy` to `false` which disables the proxy and keeps behaviour consistent with `weaver` pre-merge (as it was `weaveproxy`'s responsibility). --- prog/weaver/main.go | 21 ++++++++++++--------- proxy/proxy.go | 1 + weave | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 3f3c7bd1..db67d371 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -252,16 +252,18 @@ func main() { } config.ProtocolMinVersion = byte(protocolMinVersion) - // Start Weave Proxy: - proxy, err := weaveproxy.NewProxy(*proxyConfig) - if err != nil { - Log.Fatalf("Could not start proxy: %s", err) + if proxyConfig.Enabled { + // Start Weave Proxy: + proxy, err := weaveproxy.NewProxy(*proxyConfig) + if err != nil { + Log.Fatalf("Could not start proxy: %s", err) + } + defer proxy.Stop() + listeners := proxy.Listen() + proxy.AttachExistingContainers() + go proxy.Serve(listeners) + go proxy.ListenAndServeStatus("/home/weave/status.sock") } - defer proxy.Stop() - listeners := proxy.Listen() - proxy.AttachExistingContainers() - go proxy.Serve(listeners) - go proxy.ListenAndServeStatus("/home/weave/status.sock") if pktdebug { networkConfig.PacketLogging = packetLogging{} @@ -521,6 +523,7 @@ func configureProxy(version string, defaultDockerHost string) *weaveproxy.Config DockerBridge: getenvOrDefault("DOCKER_BRIDGE", "docker0"), DockerHost: defaultDockerHost, } + mflag.BoolVar(&proxyConfig.Enabled, []string{"-proxy"}, false, "instruct Weave Net to start its Docker proxy") mflagext.ListVar(&proxyConfig.ListenAddrs, []string{"H"}, nil, "addresses on which to listen") mflag.StringVar(&proxyConfig.HostnameFromLabel, []string{"-hostname-from-label"}, "", "Key of container label from which to obtain the container's hostname") mflag.StringVar(&proxyConfig.HostnameMatch, []string{"-hostname-match"}, "(.*)", "Regexp pattern to apply on container names (e.g. '^aws-[0-9]+-(.*)$')") diff --git a/proxy/proxy.go b/proxy/proxy.go index dae1c4ce..53d770ee 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -50,6 +50,7 @@ func dockerAPIEndpoint(endpoint string) *regexp.Regexp { } type Config struct { + Enabled bool HostnameFromLabel string HostnameMatch string HostnameReplacement string diff --git a/weave b/weave index dce12232..727a0c15 100755 --- a/weave +++ b/weave @@ -48,7 +48,7 @@ weave launch [--password ] [--trusted-subnets ,...] [--no-restart] [--resume] [--no-discovery] [--no-dns] [--ipalloc-init ] [--ipalloc-range [--ipalloc-default-subnet ]] - [--plugin] + [--plugin=false] [--proxy=false] [-H ] [--without-dns] [--no-multicast-route] [--no-rewrite-hosts] [--no-default-ipalloc] [--hostname-from-label ] @@ -1509,7 +1509,8 @@ EOF deprecation_warnings "$@" check_not_running router $CONTAINER_NAME $BASE_IMAGE check_not_running_plugin_v2 - launch --plugin "$@" + # 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" ;; env)