[proxy] Set hostname and domainname based on container name, when dns
Had to make the assert_dns_record test helper more robust against 'getent hosts' returning duplicates
This commit is contained in:
1 parent
9fddad02ad
commit
b9850ac200
3 files changed
+18
-7
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
. "github.com/weaveworks/weave/common"
|
||||
"github.com/weaveworks/weave/nameserver"
|
||||
)
|
||||
|
||||
type createContainerInterceptor struct{ proxy *Proxy }
|
||||
@@ -43,7 +44,7 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
|
||||
if err := i.setWeaveWaitEntrypoint(container.Config); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := i.setWeaveDNS(&container); err != nil {
|
||||
if err := i.setWeaveDNS(&container, r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -78,7 +79,7 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Co
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody) error {
|
||||
func (i *createContainerInterceptor) setWeaveDNS(container *createContainerRequestBody, r *http.Request) error {
|
||||
if !i.proxy.WithDNS {
|
||||
return nil
|
||||
}
|
||||
@@ -88,6 +89,14 @@ func (i *createContainerInterceptor) setWeaveDNS(container *createContainerReque
|
||||
if len(container.HostConfig.DNSSearch) == 0 {
|
||||
container.HostConfig.DNSSearch = []string{"."}
|
||||
}
|
||||
|
||||
name := r.URL.Query().Get("name")
|
||||
if container.Hostname == "" && name != "" {
|
||||
container.Hostname = name
|
||||
// TODO: Get weaveDNS domain
|
||||
container.Domainname = nameserver.DefaultLocalDomain
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user