From 79db00a90e2ba2b9e661373828fd6dcab23146e5 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 Jun 2015 10:26:11 +0100 Subject: [PATCH] Strip trailing period from hostname generated from weavedns domain. We strip at the calling point rather than in the server, because DNS servers do see the domain as ending with a '.' representing the root. --- proxy/create_container_interceptor.go | 3 ++- test/270_use_name_as_hostname_test.sh | 2 +- weave | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index b1f10522..22d29214 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -94,7 +94,8 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque name := r.URL.Query().Get("name") if container.Hostname == "" && name != "" { container.Hostname = name - container.Domainname = i.getDNSDomain() + // Strip trailing period because it's unusual to see it used on the end of a host name + container.Domainname = strings.TrimSuffix(i.getDNSDomain(), ".") } return nil diff --git a/test/270_use_name_as_hostname_test.sh b/test/270_use_name_as_hostname_test.sh index a7b4ce44..ccb0ff86 100755 --- a/test/270_use_name_as_hostname_test.sh +++ b/test/270_use_name_as_hostname_test.sh @@ -3,7 +3,7 @@ . ./config.sh NAME=c1 -DOMAIN=weave.local. +DOMAIN=weave.local HOSTNAME=$NAME-hostname.$DOMAIN # Docker inspect hostname + domainname of container $2 on host $1 diff --git a/weave b/weave index 58b58057..339a1c0e 100755 --- a/weave +++ b/weave @@ -660,7 +660,8 @@ dns_args() { DNS_ARGS="$DNS_ARG $DNS_SEARCH_ARG" if [ -n "$NAME_ARG" -a -z "$HOSTNAME_SPECIFIED" ] ; then DOMAIN=$(call_dns GET /domain 2>/dev/null) || DOMAIN=weave.local. - DNS_ARGS="$DNS_ARGS --hostname=$NAME_ARG.$DOMAIN" + # Strip trailing period off DNS domain to reduce surprise + DNS_ARGS="$DNS_ARGS --hostname=$NAME_ARG.${DOMAIN%.}" fi }