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
This commit is contained in:
Bryan Boreham committed 2017-05-12 06:56:52 +00:00
1 parent 1b8d115b63
commit 0a2521e7a4
2 files changed
+19 -10

No files matched your search

+2 -1
View File
@@ -13,6 +13,7 @@ import (
"github.com/fsouza/go-dockerclient" "github.com/fsouza/go-dockerclient"
"github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common"
weavedocker "github.com/weaveworks/weave/common/docker"
) )
var ( var (
@@ -116,7 +117,7 @@ func marshalResponseBody(r *http.Response, body interface{}) error {
return nil 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) subs := containerIDRegexp.FindStringSubmatch(path)
if subs == nil { if subs == nil {
err := fmt.Errorf("No container id found in request with path %s", path) err := fmt.Errorf("No container id found in request with path %s", path)
+17 -9
View File
@@ -76,7 +76,7 @@ type wait struct {
type Proxy struct { type Proxy struct {
sync.Mutex sync.Mutex
Config Config
client *docker.Client client *weavedocker.Client
weave *weaveapi.Client weave *weaveapi.Client
dockerBridgeIP string dockerBridgeIP string
hostnameMatchRegexp *regexp.Regexp hostnameMatchRegexp *regexp.Regexp
@@ -124,7 +124,7 @@ func (j attachJob) Stop() {
j.timer.Stop() j.timer.Stop()
} }
func NewProxy(c Config) (*Proxy, error) { func StubProxy(c Config) (*Proxy, error) {
p := &Proxy{ p := &Proxy{
Config: c, Config: c,
waiters: make(map[*http.Request]*wait), 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), 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 // We pin the protocol version to 1.18 (which corresponds to
// Docker 1.6.x; the earliest version supported by weave) in order // Docker 1.6.x; the earliest version supported by weave) in order
// to insulate ourselves from breaking changes to the API, as // to insulate ourselves from breaking changes to the API, as
@@ -146,9 +142,21 @@ func NewProxy(c Config) (*Proxy, error) {
if err != nil { if err != nil {
return nil, err 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 { if !p.WithoutDNS {
ip, err := weavenet.FindBridgeIP(c.DockerBridge, nil) ip, err := weavenet.FindBridgeIP(c.DockerBridge, nil)
@@ -169,7 +177,7 @@ func NewProxy(c Config) (*Proxy, error) {
return nil, err return nil, err
} }
client.AddObserver(p) p.client.AddObserver(p)
return p, nil return p, nil
} }