[proxy] Set hostname and domainname based on container name, when dns
Had to make the assert_dns_record test helper more robust against 'getent hosts' returning duplicates
This commit is contained in:
1 parent
9fddad02ad
commit
b9850ac200
3 files changed
+18
-7
No files matched your search
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
. "github.com/weaveworks/weave/common"
|
. "github.com/weaveworks/weave/common"
|
||||||
|
"github.com/weaveworks/weave/nameserver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type createContainerInterceptor struct{ proxy *Proxy }
|
type createContainerInterceptor struct{ proxy *Proxy }
|
||||||
@@ -43,7 +44,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
|
|||||||
if err := i.setWeaveWaitEntrypoint(container.Config); err != nil {
|
if err := i.setWeaveWaitEntrypoint(container.Config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := i.setWeaveDNS(&container); err != nil {
|
if err := i.setWeaveDNS(&container, r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,7 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody) error {
|
func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody, r *http.Request) error {
|
||||||
if !i.proxy.WithDNS {
|
if !i.proxy.WithDNS {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -88,6 +89,14 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
|||||||
if len(container.HostConfig.DNSSearch) == 0 {
|
if len(container.HostConfig.DNSSearch) == 0 {
|
||||||
container.HostConfig.DNSSearch = []string{"."}
|
container.HostConfig.DNSSearch = []string{"."}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name := r.URL.Query().Get("name")
|
||||||
|
if container.Hostname == "" && name != "" {
|
||||||
|
container.Hostname = name
|
||||||
|
// TODO: Get weaveDNS domain
|
||||||
|
container.Domainname = nameserver.DefaultLocalDomain
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,17 @@
|
|||||||
|
|
||||||
C1=10.2.0.78
|
C1=10.2.0.78
|
||||||
C2=10.2.0.34
|
C2=10.2.0.34
|
||||||
NAME=seetwo.weave.local
|
C1_NAME=c1.weave.local
|
||||||
|
C2_NAME=seetwo.weave.local
|
||||||
|
|
||||||
start_suite "Proxy registers containers with dns"
|
start_suite "Proxy registers containers with dns"
|
||||||
|
|
||||||
weave_on $HOST1 launch-dns 10.2.254.1/24
|
weave_on $HOST1 launch-dns 10.2.254.1/24
|
||||||
weave_on $HOST1 launch-proxy --with-dns
|
weave_on $HOST1 launch-proxy --with-dns
|
||||||
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C2/24 -dt --name=c2 -h $NAME $SMALL_IMAGE /bin/sh
|
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C2/24 -dt --name=c2 -h $C2_NAME $SMALL_IMAGE /bin/sh
|
||||||
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C1/24 -dt --name=c1 $DNS_IMAGE /bin/sh
|
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C1/24 -dt --name=c1 $DNS_IMAGE /bin/sh
|
||||||
|
|
||||||
assert_dns_record $HOST1 c1 $NAME $C2
|
assert_dns_record $HOST1 c1 $C2_NAME $C2
|
||||||
|
assert_dns_record $HOST1 c2 $C1_NAME $C1
|
||||||
|
|
||||||
end_suite
|
end_suite
|
||||||
+1
-1
@@ -128,7 +128,7 @@ assert_dns_record() {
|
|||||||
|
|
||||||
[ -z "$DEBUG" ] || greyly echo "Checking whether the IPs '$@' exists at $host:$container"
|
[ -z "$DEBUG" ] || greyly echo "Checking whether the IPs '$@' exists at $host:$container"
|
||||||
for ip in "$@" ; do
|
for ip in "$@" ; do
|
||||||
assert "exec_on $host $container getent hosts $ip | tr -s ' '" "$ip $name"
|
assert "exec_on $host $container getent hosts $ip | awk '{print \$2}'" "$name"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user