[proxy] Add --without-dns flag, and change meaning of --with-dns flag

This commit is contained in:
Paul Bellamy committed 2015-06-16 14:07:40 +01:00
1 parent a1cb5b16a6
commit 8873d69b77
6 files changed
+58 -18

No files matched your search

+6 -1
View File
@@ -36,7 +36,8 @@ func main() {
getopt.BoolVarLong(&c.TLSConfig.Enabled, "tls", 0, "Use TLS; implied by --tlsverify") getopt.BoolVarLong(&c.TLSConfig.Enabled, "tls", 0, "Use TLS; implied by --tlsverify")
getopt.StringVarLong(&c.TLSConfig.Key, "tlskey", 0, "Path to TLS key file") getopt.StringVarLong(&c.TLSConfig.Key, "tlskey", 0, "Path to TLS key file")
getopt.BoolVarLong(&c.TLSConfig.Verify, "tlsverify", 0, "Use TLS and verify the remote") getopt.BoolVarLong(&c.TLSConfig.Verify, "tlsverify", 0, "Use TLS and verify the remote")
getopt.BoolVarLong(&c.WithDNS, "with-dns", 'w', "instruct created containers to use weaveDNS as their nameserver") getopt.BoolVarLong(&c.WithDNS, "with-dns", 'w', "instruct created containers to always use weaveDNS as their nameserver")
getopt.BoolVarLong(&c.WithoutDNS, "without-dns", 0, "instruct created containers to never use weaveDNS as their nameserver")
getopt.BoolVarLong(&c.WithIPAM, "with-ipam", 'i', "automatically allocate addresses for containers without a WEAVE_CIDR") getopt.BoolVarLong(&c.WithIPAM, "with-ipam", 'i', "automatically allocate addresses for containers without a WEAVE_CIDR")
getopt.Parse() getopt.Parse()
@@ -45,6 +46,10 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if c.WithDNS && c.WithoutDNS {
Error.Fatalf("Cannot use both '--with-dns' and '--without-dns' flags")
}
if debug { if debug {
InitDefaultLogging(true) InitDefaultLogging(true)
} }
+9 -4
View File
@@ -81,7 +81,12 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co
} }
func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody, r *http.Request) error { func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody, r *http.Request) error {
if !i.proxy.WithDNS { if i.proxy.WithoutDNS {
return nil
}
dnsDomain, dnsRunning := i.getDNSDomain()
if !(dnsRunning || i.proxy.WithDNS) {
return nil return nil
} }
@@ -95,13 +100,13 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
if container.Hostname == "" && name != "" { if container.Hostname == "" && name != "" {
container.Hostname = name container.Hostname = name
// Strip trailing period because it's unusual to see it used on the end of a host name // Strip trailing period because it's unusual to see it used on the end of a host name
container.Domainname = strings.TrimSuffix(i.getDNSDomain(), ".") container.Domainname = strings.TrimSuffix(dnsDomain, ".")
} }
return nil return nil
} }
func (i *createContainerInterceptor) getDNSDomain() (domain string) { func (i *createContainerInterceptor) getDNSDomain() (domain string, running bool) {
domain = nameserver.DefaultLocalDomain domain = nameserver.DefaultLocalDomain
dnsContainer, err := i.proxy.client.InspectContainer("weavedns") dnsContainer, err := i.proxy.client.InspectContainer("weavedns")
if err != nil || if err != nil ||
@@ -122,7 +127,7 @@ func (i *createContainerInterceptor) getDNSDomain() (domain string) {
return return
} }
return string(b) return string(b), true
} }
func (i *createContainerInterceptor) InterceptResponse(r *http.Response) error { func (i *createContainerInterceptor) InterceptResponse(r *http.Response) error {
+2 -1
View File
@@ -37,6 +37,7 @@ type Config struct {
TLSConfig TLSConfig TLSConfig TLSConfig
Version string Version string
WithDNS bool WithDNS bool
WithoutDNS bool
WithIPAM bool WithIPAM bool
} }
@@ -61,7 +62,7 @@ func NewProxy(c Config) (*Proxy, error) {
}, },
} }
if p.WithDNS { if !p.WithoutDNS {
dockerBridgeIP, err := callWeave("docker-bridge-ip") dockerBridgeIP, err := callWeave("docker-bridge-ip")
if err != nil { if err != nil {
return nil, err return nil, err
+11 -7
View File
@@ -115,13 +115,17 @@ are handled as before.
## <a name="dns"></a>Automatic discovery ## <a name="dns"></a>Automatic discovery
Containers started via the proxy are automatically registered in Containers started via the proxy are
[weaveDNS](weavedns.html) if they have a hostname in the weaveDNS automatically registered in [weaveDNS](weavedns.html) if they have a
domain (usually `.weave.local`). In order for containers to be able to hostname in the weaveDNS domain (usually `.weave.local`). In order for
look up such names, their DNS resolver needs to be configured to point containers to be able to look up such names, their DNS resolver needs
at weaveDNS. This can be done [manually](weavedns.html#without-run), to be configured to point at weaveDNS. This will be done automatically by the proxy
or automatically by the proxy by launching it with the `--with-dns` while weaveDNS is running. To disable this launch the proxy with the `--without-dns` option, i.e.
option, i.e.
host1$ weave launch-proxy --without-dns
To enable weaveDNS resolution when weaveDNS is not running, launch the
proxy with the `--with-dns` option, i.e.
host1$ weave launch-proxy --with-dns host1$ weave launch-proxy --with-dns
+29 -4
View File
@@ -7,14 +7,39 @@ C2=10.2.0.34
C1_NAME=c1.weave.local C1_NAME=c1.weave.local
C2_NAME=seetwo.weave.local C2_NAME=seetwo.weave.local
boot_containers() {
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C2/24 -dt --name=c2 -h $C2_NAME $DNS_IMAGE /bin/sh
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C1/24 -dt --name=c1 $DNS_IMAGE /bin/sh
}
kill_containers() {
docker_on $HOST1 kill c1 c2
docker_on $HOST1 rm c1 c2
}
start_suite "Proxy registers containers with dns" start_suite "Proxy registers containers with dns"
weave_on $HOST1 launch-dns 10.2.254.1/24 $WEAVEDNS_ARGS bridge_ip=$(weave_on $HOST1 docker-bridge-ip)
weave_on $HOST1 launch-proxy --with-dns
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C2/24 -dt --name=c2 -h $C2_NAME $DNS_IMAGE /bin/sh
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C1/24 -dt --name=c1 $DNS_IMAGE /bin/sh
weave_on $HOST1 launch-proxy --with-dns
boot_containers
assert "exec_on $HOST1 c1 cat /etc/resolv.conf" "nameserver $bridge_ip"
assert "exec_on $HOST1 c2 cat /etc/resolv.conf" "nameserver $bridge_ip"
weave_on $HOST1 stop-proxy
kill_containers
weave_on $HOST1 launch-dns 10.2.254.1/24 $WEAVEDNS_ARGS
weave_on $HOST1 launch-proxy
boot_containers
assert_dns_record $HOST1 c1 $C2_NAME $C2 assert_dns_record $HOST1 c1 $C2_NAME $C2
assert_dns_record $HOST1 c2 $C1_NAME $C1 assert_dns_record $HOST1 c2 $C1_NAME $C1
weave_on $HOST1 stop-proxy
kill_containers
weave_on $HOST1 launch-proxy --without-dns
boot_containers
assert_no_dns_record $HOST1 c1 $C2_NAME
assert_no_dns_record $HOST1 c2 $C1_NAME
end_suite end_suite
+1 -1
View File
@@ -29,7 +29,7 @@ usage() {
echo "weave launch [-password <password>] [-nickname <nickname>] [-nodiscovery]" echo "weave launch [-password <password>] [-nickname <nickname>] [-nodiscovery]"
echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..." echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..."
echo "weave launch-dns [<addr>]" echo "weave launch-dns [<addr>]"
echo "weave launch-proxy [-D <endpoint>] [-H <endpoint>] [--with-dns] [--with-ipam]" echo "weave launch-proxy [-D <endpoint>] [-H <endpoint>] [--with-dns|--without-dns] [--with-ipam]"
echo "weave connect [--replace] [<peer> ...]" echo "weave connect [--replace] [<peer> ...]"
echo "weave forget <peer> ..." echo "weave forget <peer> ..."
echo "weave run [--with-dns] [<addr> ...] <docker run args> ..." echo "weave run [--with-dns] [<addr> ...] <docker run args> ..."