Merge pull request #931 from paulbellamy/weavedns_default_search_domain

[dns] resolve names in `weave.local` by default unless hostname or search path is specified
This commit is contained in:
Adam Harrison committed 2015-06-16 18:13:17 +01:00
commit b8afefa55f
5 files changed
+74 -15

No files matched your search

+8 -4
View File
@@ -92,10 +92,6 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
container.HostConfig.DNS = append(container.HostConfig.DNS, i.proxy.dockerBridgeIP) container.HostConfig.DNS = append(container.HostConfig.DNS, i.proxy.dockerBridgeIP)
if len(container.HostConfig.DNSSearch) == 0 {
container.HostConfig.DNSSearch = []string{"."}
}
name := r.URL.Query().Get("name") name := r.URL.Query().Get("name")
if container.Hostname == "" && name != "" { if container.Hostname == "" && name != "" {
container.Hostname = name container.Hostname = name
@@ -103,6 +99,14 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
container.Domainname = strings.TrimSuffix(dnsDomain, ".") container.Domainname = strings.TrimSuffix(dnsDomain, ".")
} }
if len(container.HostConfig.DNSSearch) == 0 {
if container.Hostname == "" {
container.HostConfig.DNSSearch = []string{dnsDomain}
} else {
container.HostConfig.DNSSearch = []string{"."}
}
}
return nil return nil
} }
+4 -3
View File
@@ -225,9 +225,10 @@ weaveDNS instance will receive.
If you don't supply a domain search path (with `--dns-search=`), If you don't supply a domain search path (with `--dns-search=`),
`weave run ...` tells a container to look for "bare" hostnames, like `weave run ...` tells a container to look for "bare" hostnames, like
`pingme`, in its own domain. That's why you can just invoke `ping `pingme`, in its own domain (or in `weave.local` if it has no domain).
pingme` above -- since the hostname is `ubuntu.weave.local`, it will That's why you can just invoke `ping pingme` above -- since the
look for `pingme.weave.local`. hostname is `ubuntu.weave.local`, it will look for
`pingme.weave.local`.
If you want to supply other entries for the domain search path, If you want to supply other entries for the domain search path,
e.g. if you want containers in different sub-domains to resolve e.g. if you want containers in different sub-domains to resolve
+9 -2
View File
@@ -5,6 +5,7 @@
C1=10.2.0.78 C1=10.2.0.78
C2=10.2.0.34 C2=10.2.0.34
C3=10.2.0.57 C3=10.2.0.57
C4=10.2.0.99
DOMAIN=weave.local DOMAIN=weave.local
NAME=seeone.$DOMAIN NAME=seeone.$DOMAIN
@@ -15,8 +16,14 @@ launch_dns_on $HOST1 10.2.254.1/24
start_container $HOST1 $C1/24 --name=c1 -h $NAME start_container $HOST1 $C1/24 --name=c1 -h $NAME
start_container_with_dns $HOST1 $C2/24 --name=c2 -h seetwo.$DOMAIN start_container_with_dns $HOST1 $C2/24 --name=c2 -h seetwo.$DOMAIN
start_container_with_dns $HOST1 $C3/24 --name=c3 --dns-search=$DOMAIN start_container_with_dns $HOST1 $C3/24 --name=c3 --dns-search=$DOMAIN
container=$(start_container_with_dns $HOST1 $C4/24)
assert "exec_on $HOST1 c2 getent hosts seeone | tr -s ' '" "$C1 $NAME" check() {
assert "exec_on $HOST1 c3 getent hosts seeone | tr -s ' '" "$C1 $NAME" assert "exec_on $HOST1 $1 getent hosts seeone | tr -s ' '" "$C1 $NAME"
}
check c2
check c3
check "$container"
end_suite end_suite
+34
View File
@@ -0,0 +1,34 @@
#! /bin/bash
. ./config.sh
C1=10.2.0.78
C2=10.2.0.34
C3=10.2.0.57
C4=10.2.0.99
DOMAIN=weave.local
NAME=seeone.$DOMAIN
start_container() {
proxy docker_on $HOST1 run "$@" -dt $DNS_IMAGE /bin/sh
}
start_suite "Resolve unqualified names"
weave_on $HOST1 launch-dns 10.2.254.1/24
weave_on $HOST1 launch-proxy
start_container -e WEAVE_CIDR=$C1/24 --name=c1 -h $NAME
start_container -e WEAVE_CIDR=$C2/24 --name=c2 -h seetwo.$DOMAIN
start_container -e WEAVE_CIDR=$C3/24 --name=c3 --dns-search=$DOMAIN
container=$(start_container -e WEAVE_CIDR=$C4/24)
check() {
assert "proxy exec_on $HOST1 $1 getent hosts seeone | tr -s ' '" "$C1 $NAME"
}
check c2
check c3
check "$container"
end_suite
+19 -6
View File
@@ -632,6 +632,13 @@ peer_args() {
# weaveDNS helpers # weaveDNS helpers
###################################################################### ######################################################################
# Memoized function to query the weaveDNS server for our dns domain.
dns_domain() {
DNS_DOMAIN=${DNS_DOMAIN:-$(call_dns GET /domain 2>/dev/null || true)}
DNS_DOMAIN=${DNS_DOMAIN:-weave.local.}
echo $DNS_DOMAIN
}
dns_args() { dns_args() {
if [ \( "$DOCKER_VERSION_MAJOR" -lt 1 \) -o \ if [ \( "$DOCKER_VERSION_MAJOR" -lt 1 \) -o \
\( "$DOCKER_VERSION_MAJOR" -eq 1 -a \ \( "$DOCKER_VERSION_MAJOR" -eq 1 -a \
@@ -644,16 +651,15 @@ dns_args() {
exit 1 exit 1
fi fi
docker_bridge_ip docker_bridge_ip
DNS_ARG="--dns $DOCKER_BRIDGE_IP"
DNS_SEARCH_ARG="--dns-search=."
NAME_ARG="" NAME_ARG=""
HOSTNAME_SPECIFIED= HOSTNAME_SPECIFIED=
DNS_SEARCH_SPECIFIED=
WITH_DNS= WITH_DNS=
WITHOUT_DNS= WITHOUT_DNS=
while [ $# -gt 0 ] ; do while [ $# -gt 0 ] ; do
case "$1" in case "$1" in
--dns-search=*) --dns-search=*)
DNS_SEARCH_ARG="" DNS_SEARCH_SPECIFIED=1
;; ;;
--name) --name)
NAME_ARG="$2" NAME_ARG="$2"
@@ -678,11 +684,18 @@ dns_args() {
if [ -z "$WITH_DNS" ] ; then if [ -z "$WITH_DNS" ] ; then
check_running $DNS_CONTAINER_NAME 2>/dev/null || return 0 check_running $DNS_CONTAINER_NAME 2>/dev/null || return 0
fi fi
DNS_ARGS="$DNS_ARG $DNS_SEARCH_ARG" DNS_ARGS="--dns $DOCKER_BRIDGE_IP"
if [ -n "$NAME_ARG" -a -z "$HOSTNAME_SPECIFIED" ] ; then if [ -n "$NAME_ARG" -a -z "$HOSTNAME_SPECIFIED" ] ; then
DOMAIN=$(call_dns GET /domain 2>/dev/null) || DOMAIN=weave.local. DOMAIN=$(dns_domain)
# Strip trailing period off DNS domain to reduce surprise
DNS_ARGS="$DNS_ARGS --hostname=$NAME_ARG.${DOMAIN%.}" DNS_ARGS="$DNS_ARGS --hostname=$NAME_ARG.${DOMAIN%.}"
HOSTNAME_SPECIFIED=1
fi
if [ -z "$DNS_SEARCH_SPECIFIED" ] ; then
if [ -z "$HOSTNAME_SPECIFIED" ] ; then
DNS_ARGS="$DNS_ARGS --dns-search=$(dns_domain)"
else
DNS_ARGS="$DNS_ARGS --dns-search=."
fi
fi fi
} }