From 5e9bd5424aa2cc32aa1755e3229989dfe63f5d64 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 29 Jul 2015 15:47:02 +0100 Subject: [PATCH 1/3] Removed all the imports from "code.google.com" --- prog/weaveproxy/main.go | 2 +- router/crypto.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index c896d872..d110088b 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -5,7 +5,7 @@ import ( "os" "strings" - "code.google.com/p/getopt" + "github.com/pborman/getopt" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/proxy" ) diff --git a/router/crypto.go b/router/crypto.go index 291603d1..b66d2b73 100644 --- a/router/crypto.go +++ b/router/crypto.go @@ -8,9 +8,9 @@ import ( "fmt" "sync" - "code.google.com/p/go-bit/bit" - "code.google.com/p/go.crypto/nacl/box" - "code.google.com/p/go.crypto/nacl/secretbox" + "github.com/andybalholm/go-bit" + "golang.org/x/crypto/nacl/box" + "golang.org/x/crypto/nacl/secretbox" ) func GenerateKeyPair() (publicKey, privateKey *[32]byte, err error) { From e2389a4061d04f1baacd88f1438fb21102232d66 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 30 Jul 2015 11:52:23 +0100 Subject: [PATCH 2/3] [proxy] Don't try to attach if container failed to start --- proxy/start_container_interceptor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index 803ca869..9dc1411d 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -16,6 +16,10 @@ func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error { } func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { + if r.StatusCode < 200 || r.StatusCode >= 300 { // Docker didn't do the start + return nil + } + container, err := inspectContainerInPath(i.proxy.client, r.Request.URL.Path) if err != nil { return err From 4958b8d37a6bf631537c06046188dca9bc87c5ab Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 29 Jul 2015 15:51:51 +0100 Subject: [PATCH 3/3] [proxy] Mount /w from the host for weavewaited containers We set it at container create. Had tried also setting it at start, but it seems to cause weird behaviour, and there is no way to do it from the CLI. --- proxy/create_container_interceptor.go | 14 +++++++++++- proxy/proxy.go | 31 ++++++++++++++++++++++++--- test/610_proxy_wait_for_weave_test.sh | 5 +++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index ee5c43ed..5b6bfd7b 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -53,10 +53,10 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if container.HostConfig == nil { container.HostConfig = &docker.HostConfig{} } - container.HostConfig.VolumesFrom = append(container.HostConfig.VolumesFrom, "weaveproxy:ro") if container.Config == nil { container.Config = &docker.Config{} } + i.addWeaveWaitVolume(container.HostConfig) if err := i.setWeaveWaitEntrypoint(container.Config); err != nil { return err } @@ -75,6 +75,18 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { return nil } +func (i *createContainerInterceptor) addWeaveWaitVolume(hostConfig *docker.HostConfig) { + var binds []string + for _, bind := range hostConfig.Binds { + s := strings.Split(bind, ":") + if len(s) >= 2 && s[1] == "/w" { + continue + } + binds = append(binds, bind) + } + hostConfig.Binds = append(binds, fmt.Sprintf("%s:/w:ro", i.proxy.weaveWaitVolume)) +} + func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Config) error { if len(container.Entrypoint) == 0 { image, err := i.proxy.client.InspectImage(container.Image) diff --git a/proxy/proxy.go b/proxy/proxy.go index d454a06c..b42a582d 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -3,6 +3,7 @@ package proxy import ( "crypto/tls" "errors" + "fmt" "net" "net/http" "net/url" @@ -32,9 +33,10 @@ var ( type Proxy struct { Config - dial func() (net.Conn, error) - client *docker.Client - dockerBridgeIP string + dial func() (net.Conn, error) + client *docker.Client + dockerBridgeIP string + weaveWaitVolume string } type Config struct { @@ -85,9 +87,32 @@ func NewProxy(c Config) (*Proxy, error) { return nil, err } + if err = p.findWeaveWaitVolume(); err != nil { + return nil, err + } + return p, nil } +func (proxy *Proxy) findWeaveWaitVolume() error { + container, err := proxy.client.InspectContainer("weaveproxy") + if err != nil { + return fmt.Errorf("Could not find the weavewait volume: %s", err) + } + + if container.Volumes == nil { + return fmt.Errorf("Could not find the weavewait volume") + } + + volume, ok := container.Volumes["/w"] + if !ok { + return fmt.Errorf("Could not find the weavewait volume") + } + + proxy.weaveWaitVolume = volume + return nil +} + func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { Info.Printf("%s %s", r.Method, r.URL) path := r.URL.Path diff --git a/test/610_proxy_wait_for_weave_test.sh b/test/610_proxy_wait_for_weave_test.sh index ddc63b3d..1d5e1276 100755 --- a/test/610_proxy_wait_for_weave_test.sh +++ b/test/610_proxy_wait_for_weave_test.sh @@ -28,4 +28,9 @@ assert_raises "proxy docker_on $HOST1 exec c3 true" # Check we can't modify weavewait assert_raises "proxy docker_on $HOST1 run -e 'WEAVE_CIDR=10.2.1.2/24' $BASE_IMAGE touch /w/w" 1 +# Check only user-specified volumes and /w are mounted +proxy docker_on $HOST1 create --name c4 -v /tmp/1:/srv1 -v /tmp/2:/srv2 -e 'WEAVE_CIDR=10.2.1.3/24' $BASE_IMAGE $CHECK_ETHWE_UP +proxy docker_on $HOST1 start -ai c4 +assert "docker_on $HOST1 inspect --format='{{range \$k, \$v := .Volumes}}{{\$k}} {{end}}' c4" "/srv1 /srv2 /w " + end_suite