Add groupsAsSubDomains option
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
72f88e5c0f
commit
92ca220890
4 changed files with 39 additions and 17 deletions
11
docs/toml.md
11
docs/toml.md
|
@ -636,7 +636,16 @@ domain = "marathon.localhost"
|
||||||
# Optional
|
# Optional
|
||||||
# Default: false
|
# Default: false
|
||||||
#
|
#
|
||||||
# ExposedByDefault = true
|
# exposedByDefault = true
|
||||||
|
|
||||||
|
# Convert Marathon groups to subdomains
|
||||||
|
# Default behavior: /foo/bar/myapp => foo-bar-myapp.{defaultDomain}
|
||||||
|
# with groupsAsSubDomains enabled: /foo/bar/myapp => myapp.bar.foo.{defaultDomain}
|
||||||
|
#
|
||||||
|
# Optional
|
||||||
|
# Default: false
|
||||||
|
#
|
||||||
|
# groupsAsSubDomains = true
|
||||||
|
|
||||||
# Enable Marathon basic authentication
|
# Enable Marathon basic authentication
|
||||||
#
|
#
|
||||||
|
|
|
@ -236,7 +236,7 @@ func (provider *Docker) getFrontendRule(container dockertypes.ContainerJSON) str
|
||||||
if label, err := getLabel(container, "traefik.frontend.rule"); err == nil {
|
if label, err := getLabel(container, "traefik.frontend.rule"); err == nil {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
return "Host:" + provider.getEscapedName(container.Name) + "." + provider.Domain
|
return "Host:" + provider.getSubDomain(container.Name) + "." + provider.Domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Docker) getBackend(container dockertypes.ContainerJSON) string {
|
func (provider *Docker) getBackend(container dockertypes.ContainerJSON) string {
|
||||||
|
@ -351,6 +351,6 @@ func listContainers(dockerClient client.APIClient) ([]dockertypes.ContainerJSON,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape beginning slash "/", convert all others to dash "-"
|
// Escape beginning slash "/", convert all others to dash "-"
|
||||||
func (provider *Docker) getEscapedName(name string) string {
|
func (provider *Docker) getSubDomain(name string) string {
|
||||||
return strings.Replace(strings.TrimPrefix(name, "/"), "/", "-", -1)
|
return strings.Replace(strings.TrimPrefix(name, "/"), "/", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,14 @@ import (
|
||||||
|
|
||||||
// Marathon holds configuration of the Marathon provider.
|
// Marathon holds configuration of the Marathon provider.
|
||||||
type Marathon struct {
|
type Marathon struct {
|
||||||
BaseProvider `mapstructure:",squash" description:"go through"`
|
BaseProvider
|
||||||
Endpoint string `description:"Marathon server endpoint. You can also specify multiple endpoint for Marathon"`
|
Endpoint string `description:"Marathon server endpoint. You can also specify multiple endpoint for Marathon"`
|
||||||
Domain string `description:"Default domain used"`
|
Domain string `description:"Default domain used"`
|
||||||
ExposedByDefault bool `description:"Expose Marathon apps by default"`
|
ExposedByDefault bool `description:"Expose Marathon apps by default"`
|
||||||
Basic *MarathonBasic
|
GroupsAsSubDomains bool `description:"Convert Marathon groups to subdomains"`
|
||||||
TLS *tls.Config
|
Basic *MarathonBasic
|
||||||
marathonClient marathon.Marathon
|
TLS *tls.Config
|
||||||
|
marathonClient marathon.Marathon
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarathonBasic holds basic authentication specific configurations
|
// MarathonBasic holds basic authentication specific configurations
|
||||||
|
@ -342,7 +343,7 @@ func (provider *Marathon) getFrontendRule(application marathon.Application) stri
|
||||||
if label, err := provider.getLabel(application, "traefik.frontend.rule"); err == nil {
|
if label, err := provider.getLabel(application, "traefik.frontend.rule"); err == nil {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
return "Host:" + provider.getEscapedName(application.ID) + "." + provider.Domain
|
return "Host:" + provider.getSubDomain(application.ID) + "." + provider.Domain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Marathon) getBackend(task marathon.Task, applications []marathon.Application) string {
|
func (provider *Marathon) getBackend(task marathon.Task, applications []marathon.Application) string {
|
||||||
|
@ -361,9 +362,12 @@ func (provider *Marathon) getFrontendBackend(application marathon.Application) s
|
||||||
return replace("/", "-", application.ID)
|
return replace("/", "-", application.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Marathon) getEscapedName(name string) string {
|
func (provider *Marathon) getSubDomain(name string) string {
|
||||||
splitedName := strings.Split(strings.TrimPrefix(name, "/"), "/")
|
if provider.GroupsAsSubDomains {
|
||||||
sort.Sort(sort.Reverse(sort.StringSlice(splitedName)))
|
splitedName := strings.Split(strings.TrimPrefix(name, "/"), "/")
|
||||||
reverseName := strings.Join(splitedName, ".")
|
sort.Sort(sort.Reverse(sort.StringSlice(splitedName)))
|
||||||
return reverseName
|
reverseName := strings.Join(splitedName, ".")
|
||||||
|
return reverseName
|
||||||
|
}
|
||||||
|
return strings.Replace(strings.TrimPrefix(name, "/"), "/", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,16 @@
|
||||||
# Optional
|
# Optional
|
||||||
# Default: false
|
# Default: false
|
||||||
#
|
#
|
||||||
# ExposedByDefault = true
|
# exposedByDefault = true
|
||||||
|
|
||||||
|
# Convert Marathon groups to subdomains
|
||||||
|
# Default behavior: /foo/bar/myapp => foo-bar-myapp.{defaultDomain}
|
||||||
|
# with groupsAsSubDomains enabled: /foo/bar/myapp => myapp.bar.foo.{defaultDomain}
|
||||||
|
#
|
||||||
|
# Optional
|
||||||
|
# Default: false
|
||||||
|
#
|
||||||
|
# groupsAsSubDomains = true
|
||||||
|
|
||||||
# Enable Marathon basic authentication
|
# Enable Marathon basic authentication
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue