From 0a2521e7a46367a6b629ebbd9cab0cd5c69dc0a8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 10 May 2017 08:54:25 +0100 Subject: [PATCH] Introduce StubProxy() so weaveutil can call functions on it implies change type of docker client to weavedocker so we can call things like Info() on it --- proxy/common.go | 3 ++- proxy/proxy.go | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/proxy/common.go b/proxy/common.go index 80e04ff4..e94a8565 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -13,6 +13,7 @@ import ( "github.com/fsouza/go-dockerclient" "github.com/weaveworks/weave/common" + weavedocker "github.com/weaveworks/weave/common/docker" ) var ( @@ -116,7 +117,7 @@ func marshalResponseBody(r *http.Response, body interface{}) error { return nil } -func inspectContainerInPath(client *docker.Client, path string) (*docker.Container, error) { +func inspectContainerInPath(client *weavedocker.Client, path string) (*docker.Container, error) { subs := containerIDRegexp.FindStringSubmatch(path) if subs == nil { err := fmt.Errorf("No container id found in request with path %s", path) diff --git a/proxy/proxy.go b/proxy/proxy.go index 1777194d..aba1bf1e 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -76,7 +76,7 @@ type wait struct { type Proxy struct { sync.Mutex Config - client *docker.Client + client *weavedocker.Client weave *weaveapi.Client dockerBridgeIP string hostnameMatchRegexp *regexp.Regexp @@ -124,7 +124,7 @@ func (j attachJob) Stop() { j.timer.Stop() } -func NewProxy(c Config) (*Proxy, error) { +func StubProxy(c Config) (*Proxy, error) { p := &Proxy{ Config: c, waiters: make(map[*http.Request]*wait), @@ -133,10 +133,6 @@ func NewProxy(c Config) (*Proxy, error) { weave: weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log), } - if err := p.TLSConfig.LoadCerts(); err != nil { - Log.Fatalf("Could not configure tls for proxy: %s", err) - } - // We pin the protocol version to 1.18 (which corresponds to // Docker 1.6.x; the earliest version supported by weave) in order // to insulate ourselves from breaking changes to the API, as @@ -146,9 +142,21 @@ func NewProxy(c Config) (*Proxy, error) { if err != nil { return nil, err } - Log.Info(client.Info()) + p.client = client + return p, nil +} - p.client = client.Client +func NewProxy(c Config) (*Proxy, error) { + p, err := StubProxy(c) + if err != nil { + return nil, err + } + + if err := p.TLSConfig.LoadCerts(); err != nil { + Log.Fatalf("Could not configure tls for proxy: %s", err) + } + + Log.Info(p.client.Info()) if !p.WithoutDNS { ip, err := weavenet.FindBridgeIP(c.DockerBridge, nil) @@ -169,7 +177,7 @@ func NewProxy(c Config) (*Proxy, error) { return nil, err } - client.AddObserver(p) + p.client.AddObserver(p) return p, nil }