[proxy] More flexible container name -> hostname derivation
Provides to new two new flags: `--hostname-match <regexp>` and `--hostname-replacement <replacement>`. When launching a container, its name matched against regular expression `<regexp>`. Then, based on that match, `<replacement>` will be used to generate a hostname, which will ultimately be handed over to weaveDNS for registration. The substitution is implemented with https://golang.org/pkg/regexp/#Regexp.ReplaceAllString . Thus, references to regexp substitution groups should be prepended with a dollar sign. For instance, if we provide `--hostname-match '^aws-[0-9]+-(.*)$'` and `--hostname-replacement 'my-app-$1'`, running a container named `aws-12798186823-foo` through WeaveProxy will lead to WeaveDNS registering `my-app-foo`. Closes #1018
This commit is contained in:
1 parent
bbacaa42b8
commit
4f82dc97fd
6 files changed
+92
-15
No files matched your search
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#! /bin/bash
|
||||
|
||||
. ./config.sh
|
||||
|
||||
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
|
||||
|
||||
start_container() {
|
||||
proxy docker_on $HOST1 run "$@" -dt $DNS_IMAGE /bin/sh
|
||||
}
|
||||
|
||||
start_suite "Hostname derivation through container name substitutions"
|
||||
|
||||
weave_on $HOST1 launch-dns 10.2.254.1/24
|
||||
weave_on $HOST1 launch-proxy --hostname-match '^[^-]+-(?P<appname>[^-]*)-[^-]+$' --hostname-replacement '$appname'
|
||||
|
||||
start_container -e WEAVE_CIDR=$C1/24 --name=$CNAME1
|
||||
start_container -e WEAVE_CIDR=$C2/24 --name=$CNAME2
|
||||
start_container -e WEAVE_CIDR=$C3/24 --name=$CNAME3
|
||||
|
||||
assert_dns_a_record $HOST1 $CNAME1 $NAME2 $C2
|
||||
assert_dns_a_record $HOST1 $CNAME2 $NAME3 $C3
|
||||
assert_dns_a_record $HOST1 $CNAME3 $NAME1 $C1
|
||||
|
||||
end_suite
|
||||
Reference in new issue
Block a user