From cb73b738621d57727072ae998cdeaec337f23a1a Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 27 May 2015 10:09:29 +0100 Subject: [PATCH] Fix bug of --with-ipam not setting entrypoints --- proxy/create_container_interceptor.go | 3 ++- proxy/create_exec_interceptor.go | 5 +++-- proxy/proxy.go | 4 ++-- test/620_proxy_entrypoint_command_test.sh | 6 ++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 2aa8c4dd..3aae2df4 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -15,6 +15,7 @@ type createContainerInterceptor struct { client *docker.Client withDNS bool dockerBridgeIP string + withIPAM bool } type createContainerRequestBody struct { @@ -35,7 +36,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { return err } - if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok { + if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok || i.withIPAM { Info.Printf("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " ")) container.HostConfig.VolumesFrom = append(container.HostConfig.VolumesFrom, "weaveproxy") if err := i.setWeaveWaitEntrypoint(container.Config); err != nil { diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index 00050115..e3a9bc30 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -11,7 +11,8 @@ import ( ) type createExecInterceptor struct { - client *docker.Client + client *docker.Client + withIPAM bool } type createExecRequestBody struct { @@ -37,7 +38,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { return err } - if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok { + if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok || i.withIPAM { Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) options.Cmd = append(weaveWaitEntrypoint, options.Cmd...) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 03ba90eb..ee820a21 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -68,11 +68,11 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { path := r.URL.Path switch { case containerCreateRegexp.MatchString(path): - proxy.serveWithInterceptor(&createContainerInterceptor{proxy.client, proxy.withDNS, proxy.dockerBridgeIP}, w, r) + proxy.serveWithInterceptor(&createContainerInterceptor{proxy.client, proxy.withDNS, proxy.dockerBridgeIP, proxy.withIPAM}, w, r) case containerStartRegexp.MatchString(path): proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.withDNS, proxy.withIPAM}, w, r) case execCreateRegexp.MatchString(path): - proxy.serveWithInterceptor(&createExecInterceptor{proxy.client}, w, r) + proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.withIPAM}, w, r) case strings.HasPrefix(path, "/weave"): w.WriteHeader(http.StatusOK) default: diff --git a/test/620_proxy_entrypoint_command_test.sh b/test/620_proxy_entrypoint_command_test.sh index 73c6401c..e03b9a10 100755 --- a/test/620_proxy_entrypoint_command_test.sh +++ b/test/620_proxy_entrypoint_command_test.sh @@ -26,4 +26,10 @@ run_container "grep ^1$ /sys/class/net/ethwe/carrier" build_image false '["/bin/false"]' '' run_container "--entrypoint='grep' false ^1$ /sys/class/net/ethwe/carrier" +weave_on $HOST1 launch -iprange 10.2.2.0/24 +docker_on $HOST1 kill weaveproxy +weave_on $HOST1 launch-proxy --with-ipam + +assert_raises "proxy docker_on $HOST1 run check-ethwe-up" + end_suite