[proxy] do not weave attach containers in '--net=host|container:<name|id>'
This commit is contained in:
1 parent
77bc56751b
commit
1132d26d47
5 files changed
+17
-4
No files matched your search
@@ -46,7 +46,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok {
|
||||
if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig); ok {
|
||||
Info.Printf("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " "))
|
||||
if container.HostConfig == nil {
|
||||
container.HostConfig = &docker.HostConfig{}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
|
||||
}
|
||||
|
||||
_, hasWeaveWait := container.Volumes["/w"]
|
||||
cidrs, hasCIDRs := i.proxy.weaveCIDRsFromConfig(container.Config)
|
||||
cidrs, hasCIDRs := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig)
|
||||
if hasCIDRs && hasWeaveWait {
|
||||
Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
|
||||
cmd := append(weaveWaitEntrypoint, "-s")
|
||||
|
||||
+6
-1
@@ -115,7 +115,12 @@ func (proxy *Proxy) ListenAndServe() error {
|
||||
return (&http.Server{Handler: proxy}).Serve(listener)
|
||||
}
|
||||
|
||||
func (proxy *Proxy) weaveCIDRsFromConfig(config *docker.Config) ([]string, bool) {
|
||||
func (proxy *Proxy) weaveCIDRsFromConfig(config *docker.Config, hostConfig *docker.HostConfig) ([]string, bool) {
|
||||
if hostConfig != nil &&
|
||||
hostConfig.NetworkMode != "" &&
|
||||
hostConfig.NetworkMode != "bridge" {
|
||||
return nil, false
|
||||
}
|
||||
for _, e := range config.Env {
|
||||
if strings.HasPrefix(e, "WEAVE_CIDR=") {
|
||||
if e[11:] == "none" {
|
||||
|
||||
@@ -21,7 +21,7 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config)
|
||||
cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig)
|
||||
if !ok {
|
||||
Debug.Print("No Weave CIDR, ignoring")
|
||||
return nil
|
||||
|
||||
@@ -26,13 +26,21 @@ start $HOST1 --name=auto
|
||||
start $HOST1 --name=none -e WEAVE_CIDR=none
|
||||
start $HOST2 --name=zero -e WEAVE_CIDR=
|
||||
start $HOST2 --name=no-default
|
||||
start $HOST1 --name=bridge --net=bridge
|
||||
start $HOST1 --name=host --net=host
|
||||
start $HOST1 --name=other --net=container:auto
|
||||
|
||||
AUTO=$(container_ip $HOST1 auto)
|
||||
ZERO=$(container_ip $HOST2 zero)
|
||||
BRIDGE=$(container_ip $HOST1 bridge)
|
||||
OTHER=$(container_ip $HOST1 other)
|
||||
assert_raises "proxy exec_on $HOST1 auto $PING $ZERO"
|
||||
assert_raises "proxy exec_on $HOST2 zero $PING $AUTO"
|
||||
assert_raises "proxy exec_on $HOST2 zero $PING $BRIDGE"
|
||||
assert_raises "proxy exec_on $HOST2 zero $PING $OTHER"
|
||||
|
||||
assert_no_ethwe $HOST1 none
|
||||
assert_no_ethwe $HOST2 no-default
|
||||
assert_no_ethwe $HOST1 host
|
||||
|
||||
end_suite
|
||||
Reference in new issue
Block a user