[proxy] Add --hostname-from-label

This allows registering container hostnames based on a label provided when
creating the container.
This commit is contained in:
Alfonso Acosta authored and Paul Bellamy committed 2015-09-04 17:02:07 +01:00
1 parent 32a82f2d0e
commit ce5dd847e9
6 files changed
+92 -29

No files matched your search

+55 -14
View File
@@ -5,24 +5,65 @@
C1=10.2.0.78
C2=10.2.0.34
C3=10.2.0.57
CNAME1=qiuds71y827hdi-seeone-1io9qd9i0wd
NAME1=seeone.weave.local
CNAME2=124DJKSNK812-seetwo-128hbaJ881
NAME2=seetwo.weave.local
CNAME3=doesnotmatchpattern
NAME3=doesnotmatchpattern.weave.local
ENAME1=qiuds71y827hdi-seeone-1io9qd9i0wd
HNAME1=seeone
FQDN1=seeone.weave.local
ENAME2=124DJKSNK812-seetwo-128hbaJ881
HNAME2=seetwo
FQDN2=$HNAME2.weave.local
ENAME3=doesnotmatchpattern
HNAME3=doesnotmatchpattern
FQDN3=$HNAME3.weave.local
start_suite "Hostname derivation through container name substitutions"
EXPANDED_NAMES="$ENAME1 $ENAME2 $ENAME3"
HOSTNAMES="$HNAME1 $HNAME2 $HNAME3"
check_dns_records() {
ARG_PREFIX=$1
shift
CID1=$(proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C1/24 ${ARG_PREFIX}$1)
CID2=$(proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C2/24 ${ARG_PREFIX}$2)
CID3=$(proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C3/24 ${ARG_PREFIX}$3)
assert_dns_a_record $HOST1 $CID1 $FQDN1 $C1
assert_dns_a_record $HOST1 $CID2 $FQDN3 $C3
assert_dns_a_record $HOST1 $CID2 $FQDN2 $C2
rm_containers $HOST1 $CID1 $CID2 $CID3
}
test_setup() {
weave_on $HOST1 launch-proxy $@
}
test_cleanup() {
weave_on $HOST1 stop-proxy
}
start_suite "Hostname derivation"
weave_on $HOST1 launch-router
weave_on $HOST1 launch-proxy --hostname-match '^[^-]+-(?P<appname>[^-]*)-[^-]+$' --hostname-replacement '$appname'
proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C1/24 --name=$CNAME1
proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C2/24 --name=$CNAME2
proxy_start_container_with_dns $HOST1 -e WEAVE_CIDR=$C3/24 --name=$CNAME3
# Hostname derivation through container name substitutions
test_setup --hostname-match '^[^-]+-(?P<appname>[^-]*)-[^-]+$' --hostname-replacement '$appname'
# check that the normal container_name->hostname derivation doesn't break
check_dns_records --name= $HOSTNAMES
check_dns_records --name= $EXPANDED_NAMES
test_cleanup
assert_dns_a_record $HOST1 $CNAME1 $NAME2 $C2
assert_dns_a_record $HOST1 $CNAME2 $NAME3 $C3
assert_dns_a_record $HOST1 $CNAME3 $NAME1 $C1
# Hostname derivation from container labels
test_setup --hostname-from-label hostname-label
check_dns_records --name= $HOSTNAMES
check_dns_records --label=hostname-label= $HOSTNAMES
test_cleanup
# Hostname derivation combining container labels and substitutions
test_setup --hostname-from-label hostname-label --hostname-match '^[^-]+-(?P<appname>[^-]*)-[^-]+$' --hostname-replacement '$appname'
check_dns_records --name= $HOSTNAMES
check_dns_records --name= $EXPANDED_NAMES
check_dns_records --label=hostname-label= $HOSTNAMES
check_dns_records --label=hostname-label= $EXPANDED_NAMES
test_cleanup
end_suite