Proxy support for IPAM
Pass `-e WEAVE_CIDR=` to your container to use IPAM. If IPAM is not enabled on the weave router, the container will be booted without weave networking. I'm not crazy about adding *another* undocumented weave cli command (ipam-cidr), but it saves the proxy messing around finding container IPs.
This commit is contained in:
1 parent
22b8f482ea
commit
46bdd8c67d
5 files changed
+37
-2
No files matched your search
+1
-2
@@ -31,8 +31,7 @@ func callWeave(args ...string) ([]byte, error) {
|
||||
func weaveCIDRsFromConfig(config *docker.Config) ([]string, bool) {
|
||||
for _, e := range config.Env {
|
||||
if strings.HasPrefix(e, "WEAVE_CIDR=") {
|
||||
result := strings.Trim(e[11:], " ")
|
||||
return strings.Split(strings.TrimSpace(result), " "), result != ""
|
||||
return strings.Fields(e[11:]), true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
|
||||
@@ -28,6 +28,14 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
|
||||
Debug.Print("No Weave CIDR, ignoring")
|
||||
return nil
|
||||
}
|
||||
if len(cidrs) == 0 {
|
||||
ipamCIDR, err := callWeave("ipam-cidr", container.ID)
|
||||
if err != nil {
|
||||
Warning.Printf("Determining container %s IP via IPAM failed: %v, %v", container.ID, err, string(ipamCIDR))
|
||||
return nil
|
||||
}
|
||||
cidrs = strings.Fields(string(ipamCIDR))
|
||||
}
|
||||
Info.Printf("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " "))
|
||||
args := []string{"attach"}
|
||||
args = append(args, cidrs...)
|
||||
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#! /bin/bash
|
||||
|
||||
. ./config.sh
|
||||
|
||||
UNIVERSE=10.2.2.0/24
|
||||
|
||||
start_suite "Ping proxied containers over cross-host weave network (with IPAM)"
|
||||
|
||||
weave_on $HOST1 launch -iprange $UNIVERSE
|
||||
weave_on $HOST1 launch-proxy
|
||||
weave_on $HOST2 launch -iprange $UNIVERSE $HOST1
|
||||
weave_on $HOST2 launch-proxy
|
||||
|
||||
proxy_start_container $HOST1 -e WEAVE_CIDR= --name=c1
|
||||
proxy_start_container $HOST2 -e WEAVE_CIDR= --name=c2
|
||||
C2=$(container_ip $HOST2 c2)
|
||||
assert_raises "exec_on $HOST1 c1 $PING $C2"
|
||||
|
||||
end_suite
|
||||
@@ -112,6 +112,12 @@ start_container() {
|
||||
weave_on $host run "$@" -t gliderlabs/alpine /bin/sh
|
||||
}
|
||||
|
||||
proxy_start_container() {
|
||||
host=$1
|
||||
shift 1
|
||||
docker -H tcp://$host:12375 run "$@" -dt gliderlabs/alpine /bin/sh
|
||||
}
|
||||
|
||||
start_container_with_dns() {
|
||||
host=$1
|
||||
shift 1
|
||||
|
||||
Reference in new issue
Block a user