From e7f30106c04e7237136aaf5ec3de2990f10f85b0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 9 Dec 2017 18:06:16 +0000 Subject: [PATCH] Pass the WeaveDNS Domain into the proxy instead of obtaining it via the http api --- prog/weaver/main.go | 1 + proxy/create_container_interceptor.go | 6 +++--- proxy/proxy.go | 9 +-------- proxy/start_container_interceptor.go | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index be265c4b..2beb205f 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -272,6 +272,7 @@ func main() { var err error if proxyConfig.Enabled { proxyConfig.DNSListenAddress = dnsConfig.addressOnly() + proxyConfig.DNSDomain = dnsConfig.Domain if noDNS { proxyConfig.WithoutDNS = true } diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 2ca525ac..38afa748 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -68,11 +68,11 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if err != nil { return err } - if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" { - if err := i.setHostname(container, hostname, dnsDomain); err != nil { + if !i.proxy.WithoutDNS { + if err := i.setHostname(container, hostname, i.proxy.DNSDomain); err != nil { return err } - if err := i.proxy.setWeaveDNS(hostConfig, hostname, dnsDomain); err != nil { + if err := i.proxy.setWeaveDNS(hostConfig, hostname, i.proxy.DNSDomain); err != nil { return err } } diff --git a/proxy/proxy.go b/proxy/proxy.go index 052e4222..91b61c58 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -62,6 +62,7 @@ type Config struct { TLSConfig TLSConfig WithoutDNS bool DNSListenAddress string + DNSDomain string NoMulticastRoute bool KeepTXOn bool DockerBridge string @@ -603,14 +604,6 @@ func (proxy *Proxy) setWeaveDNS(hostConfig jsonObject, hostname, dnsDomain strin return nil } -func (proxy *Proxy) getDNSDomain() string { - if proxy.WithoutDNS { - return "" - } - domain, _ := proxy.weave.DNSDomain() - return domain -} - func (proxy *Proxy) updateContainerNetworkSettings(container jsonObject) error { containerID, err := container.String("Id") if err != nil { diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index cec672dc..2cc1d6f7 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -50,8 +50,8 @@ func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error { return err } } - if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" { - if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, dnsDomain); err != nil { + if !i.proxy.WithoutDNS { + if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, i.proxy.DNSDomain); err != nil { return err } }