Merge pull request #1126 from weaveworks/issues/1018-more-flexible-hostname-derivation

[proxy] More flexible container name -> hostname derivation

Closes #1018.
This commit is contained in:
Matthias Radestock committed 2015-07-14 17:31:53 +01:00
commit 7ae06ef00d
6 files changed
+86 -10

No files matched your search

+3 -1
View File
@@ -60,7 +60,9 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error {
if err := i.setWeaveWaitEntrypoint(container.Config); err != nil {
return err
}
if err := i.setWeaveDNS(&container, r.URL.Query().Get("name")); err != nil {
containerName := r.URL.Query().Get("name")
hostname := i.proxy.hostnameMatchRegexp.ReplaceAllString(containerName, i.proxy.HostnameReplacement)
if err := i.setWeaveDNS(&container, hostname); err != nil {
return err
}
}
+18 -9
View File
@@ -29,19 +29,22 @@ var (
)
type Config struct {
ListenAddrs []string
NoDefaultIPAM bool
NoRewriteHosts bool
TLSConfig TLSConfig
Version string
WithDNS bool
WithoutDNS bool
HostnameMatch string
HostnameReplacement string
ListenAddrs []string
NoDefaultIPAM bool
NoRewriteHosts bool
TLSConfig TLSConfig
Version string
WithDNS bool
WithoutDNS bool
}
type Proxy struct {
Config
client *docker.Client
dockerBridgeIP string
client *docker.Client
dockerBridgeIP string
hostnameMatchRegexp *regexp.Regexp
}
func NewProxy(c Config) (*Proxy, error) {
@@ -65,6 +68,12 @@ func NewProxy(c Config) (*Proxy, error) {
p.dockerBridgeIP = string(dockerBridgeIP)
}
p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)
if err != nil {
err := fmt.Errorf("Incorrect hostname match '%s': %s", c.HostnameMatch, err.Error())
return nil, err
}
return p, nil
}