Skip to content

Commit

Permalink
Fix bug of --with-ipam not setting entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed May 27, 2015
1 parent 84aa629 commit be254ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion proxy/create_container_interceptor.go
Expand Up @@ -15,6 +15,7 @@ type createContainerInterceptor struct {
client *docker.Client
withDNS bool
dockerBridgeIP string
withIPAM bool
}

type createContainerRequestBody struct {
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions proxy/create_exec_interceptor.go
Expand Up @@ -11,7 +11,8 @@ import (
)

type createExecInterceptor struct {
client *docker.Client
client *docker.Client
withIPAM bool
}

type createExecRequestBody struct {
Expand All @@ -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...)
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/proxy.go
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions test/620_proxy_entrypoint_command_test.sh
Expand Up @@ -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 $HOST2 launch-proxy --with-ipam

assert_raises "proxy docker_on $HOST1 run grep ^1$ /sys/class/net/ethwe/carrier"

end_suite

0 comments on commit be254ac

Please sign in to comment.