Merge remote-tracking branch 'upstream/1.0'
Conflicts: proxy/create_container_interceptor.go proxy/create_exec_interceptor.go proxy/proxy.go proxy/start_container_interceptor.go
This commit is contained in:
commit
a0876becbc
5 files changed
+38
-13
No files matched your search
@@ -25,9 +25,9 @@ type createContainerRequestBody struct {
|
|||||||
MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty"`
|
MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replacement for docker.NoSuchImage, which does not contain the
|
// ErrNoSuchImage replaces docker.NoSuchImage, which does not contain the image
|
||||||
// image name, which in turn breaks docker clients post 1.7.0 since
|
// name, which in turn breaks docker clients post 1.7.0 since they expect the
|
||||||
// they expect the image name to be present in errors.
|
// image name to be present in errors.
|
||||||
type ErrNoSuchImage struct {
|
type ErrNoSuchImage struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,9 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config); ok {
|
if cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig); err != nil {
|
||||||
|
Log.Infof("Ignoring container due to %s", err)
|
||||||
|
} else {
|
||||||
Log.Infof("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " "))
|
Log.Infof("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " "))
|
||||||
if container.HostConfig == nil {
|
if container.HostConfig == nil {
|
||||||
container.HostConfig = &docker.HostConfig{}
|
container.HostConfig = &docker.HostConfig{}
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, hasWeaveWait := container.Volumes["/w"]
|
_, hasWeaveWait := container.Volumes["/w"]
|
||||||
cidrs, hasCIDRs := i.proxy.weaveCIDRsFromConfig(container.Config)
|
cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig)
|
||||||
if hasCIDRs && hasWeaveWait {
|
if err != nil {
|
||||||
|
Log.Infof("Ignoring container %s due to %s", container.ID, err)
|
||||||
|
} else if hasWeaveWait {
|
||||||
Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
|
Log.Infof("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " "))
|
||||||
cmd := append(weaveWaitEntrypoint, "-s")
|
cmd := append(weaveWaitEntrypoint, "-s")
|
||||||
options.Cmd = append(cmd, options.Cmd...)
|
options.Cmd = append(cmd, options.Cmd...)
|
||||||
|
|||||||
+17
-4
@@ -2,6 +2,7 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -26,6 +27,10 @@ var (
|
|||||||
containerCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/create$")
|
containerCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/create$")
|
||||||
containerStartRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/(re)?start$")
|
containerStartRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/(re)?start$")
|
||||||
execCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/exec$")
|
execCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/exec$")
|
||||||
|
|
||||||
|
ErrInvalidNetworkMode = errors.New("--net option")
|
||||||
|
ErrWeaveCIDRNone = errors.New("WEAVE_CIDR=none")
|
||||||
|
ErrNoDefaultIPAM = errors.New("--no-default-ipam option")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -191,14 +196,22 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) {
|
|||||||
return listener, fmt.Sprintf("%s://%s", proto, addr), nil
|
return listener, fmt.Sprintf("%s://%s", proto, addr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) weaveCIDRsFromConfig(config *docker.Config) ([]string, bool) {
|
func (proxy *Proxy) weaveCIDRsFromConfig(config *docker.Config, hostConfig *docker.HostConfig) ([]string, error) {
|
||||||
|
if hostConfig != nil &&
|
||||||
|
hostConfig.NetworkMode != "" &&
|
||||||
|
hostConfig.NetworkMode != "bridge" {
|
||||||
|
return nil, ErrInvalidNetworkMode
|
||||||
|
}
|
||||||
for _, e := range config.Env {
|
for _, e := range config.Env {
|
||||||
if strings.HasPrefix(e, "WEAVE_CIDR=") {
|
if strings.HasPrefix(e, "WEAVE_CIDR=") {
|
||||||
if e[11:] == "none" {
|
if e[11:] == "none" {
|
||||||
return nil, false
|
return nil, ErrWeaveCIDRNone
|
||||||
}
|
}
|
||||||
return strings.Fields(e[11:]), true
|
return strings.Fields(e[11:]), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, !proxy.NoDefaultIPAM
|
if proxy.NoDefaultIPAM {
|
||||||
|
return nil, ErrNoDefaultIPAM
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -21,9 +21,9 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config)
|
cidrs, err := i.proxy.weaveCIDRsFromConfig(container.Config, container.HostConfig)
|
||||||
if !ok {
|
if err != nil {
|
||||||
Log.Debug("No Weave CIDR, ignoring")
|
Log.Infof("Ignoring container %s due to %s", container.ID, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " "))
|
Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " "))
|
||||||
|
|||||||
@@ -26,13 +26,21 @@ start $HOST1 --name=auto
|
|||||||
start $HOST1 --name=none -e WEAVE_CIDR=none
|
start $HOST1 --name=none -e WEAVE_CIDR=none
|
||||||
start $HOST2 --name=zero -e WEAVE_CIDR=
|
start $HOST2 --name=zero -e WEAVE_CIDR=
|
||||||
start $HOST2 --name=no-default
|
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)
|
AUTO=$(container_ip $HOST1 auto)
|
||||||
ZERO=$(container_ip $HOST2 zero)
|
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 $HOST1 auto $PING $ZERO"
|
||||||
assert_raises "proxy exec_on $HOST2 zero $PING $AUTO"
|
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 $HOST1 none
|
||||||
assert_no_ethwe $HOST2 no-default
|
assert_no_ethwe $HOST2 no-default
|
||||||
|
assert_no_ethwe $HOST1 host
|
||||||
|
|
||||||
end_suite
|
end_suite
|
||||||
Reference in new issue
Block a user