[proxy] Add --without-dns flag, and change meaning of --with-dns flag
This commit is contained in:
1 parent
a1cb5b16a6
commit
8873d69b77
6 files changed
+58
-18
No files matched your search
@@ -36,7 +36,8 @@ func main() {
|
||||
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.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.Parse()
|
||||
|
||||
@@ -45,6 +46,10 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if c.WithDNS && c.WithoutDNS {
|
||||
Error.Fatalf("Cannot use both '--with-dns' and '--without-dns' flags")
|
||||
}
|
||||
|
||||
if debug {
|
||||
InitDefaultLogging(true)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,12 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -95,13 +100,13 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
||||
if container.Hostname == "" && name != "" {
|
||||
container.Hostname = 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
|
||||
}
|
||||
|
||||
func (i *createContainerInterceptor) getDNSDomain() (domain string) {
|
||||
func (i *createContainerInterceptor) getDNSDomain() (domain string, running bool) {
|
||||
domain = nameserver.DefaultLocalDomain
|
||||
dnsContainer, err := i.proxy.client.InspectContainer("weavedns")
|
||||
if err != nil ||
|
||||
@@ -122,7 +127,7 @@ func (i *createContainerInterceptor) getDNSDomain() (domain string) {
|
||||
return
|
||||
}
|
||||
|
||||
return string(b)
|
||||
return string(b), true
|
||||
}
|
||||
|
||||
func (i *createContainerInterceptor) InterceptResponse(r *http.Response) error {
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ type Config struct {
|
||||
TLSConfig TLSConfig
|
||||
Version string
|
||||
WithDNS bool
|
||||
WithoutDNS 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")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+11
-7
@@ -115,13 +115,17 @@ are handled as before.
|
||||
|
||||
## <a name="dns"></a>Automatic discovery
|
||||
|
||||
Containers started via the proxy are automatically registered in
|
||||
[weaveDNS](weavedns.html) if they have a hostname in the weaveDNS
|
||||
domain (usually `.weave.local`). In order for containers to be able to
|
||||
look up such names, their DNS resolver needs to be configured to point
|
||||
at weaveDNS. This can be done [manually](weavedns.html#without-run),
|
||||
or automatically by the proxy by launching it with the `--with-dns`
|
||||
option, i.e.
|
||||
Containers started via the proxy are
|
||||
automatically registered in [weaveDNS](weavedns.html) if they have a
|
||||
hostname in the weaveDNS domain (usually `.weave.local`). In order for
|
||||
containers to be able to look up such names, their DNS resolver needs
|
||||
to be configured to point at weaveDNS. This will be done automatically by the proxy
|
||||
while weaveDNS is running. To disable this launch the proxy with the `--without-dns` 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
|
||||
|
||||
|
||||
@@ -7,14 +7,39 @@ C2=10.2.0.34
|
||||
C1_NAME=c1.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"
|
||||
|
||||
weave_on $HOST1 launch-dns 10.2.254.1/24 $WEAVEDNS_ARGS
|
||||
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
|
||||
bridge_ip=$(weave_on $HOST1 docker-bridge-ip)
|
||||
|
||||
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 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
|
||||
@@ -29,7 +29,7 @@ usage() {
|
||||
echo "weave launch [-password <password>] [-nickname <nickname>] [-nodiscovery]"
|
||||
echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..."
|
||||
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 forget <peer> ..."
|
||||
echo "weave run [--with-dns] [<addr> ...] <docker run args> ..."
|
||||
|
||||
Reference in new issue
Block a user