Merge pull request #171 from tayzlor/fix-170-marathon-getbackend
Fix #170 - getBackend for marathon plugin
This commit is contained in:
commit
901c9b29bc
3 changed files with 36 additions and 2 deletions
|
@ -80,6 +80,7 @@ func (provider *Marathon) Provide(configurationChan chan<- types.ConfigMessage)
|
||||||
|
|
||||||
func (provider *Marathon) loadMarathonConfig() *types.Configuration {
|
func (provider *Marathon) loadMarathonConfig() *types.Configuration {
|
||||||
var MarathonFuncMap = template.FuncMap{
|
var MarathonFuncMap = template.FuncMap{
|
||||||
|
"getBackend": provider.getBackend,
|
||||||
"getPort": provider.getPort,
|
"getPort": provider.getPort,
|
||||||
"getWeight": provider.getWeight,
|
"getWeight": provider.getWeight,
|
||||||
"getDomain": provider.getDomain,
|
"getDomain": provider.getDomain,
|
||||||
|
@ -302,3 +303,10 @@ func (provider *Marathon) getFrontendRule(application marathon.Application) stri
|
||||||
}
|
}
|
||||||
return "Host"
|
return "Host"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (provider *Marathon) getBackend(application marathon.Application) string {
|
||||||
|
if label, err := provider.getLabel(application, "traefik.backend"); err == nil {
|
||||||
|
return label
|
||||||
|
}
|
||||||
|
return replace("/", "-", application.ID)
|
||||||
|
}
|
||||||
|
|
|
@ -800,3 +800,29 @@ func TestMarathonGetFrontendRule(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMarathonGetBackend(t *testing.T) {
|
||||||
|
provider := &Marathon{}
|
||||||
|
|
||||||
|
applications := []struct {
|
||||||
|
application marathon.Application
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
application: marathon.Application{
|
||||||
|
ID: "foo",
|
||||||
|
Labels: map[string]string{
|
||||||
|
"traefik.backend": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: "bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range applications {
|
||||||
|
actual := provider.getBackend(a.application)
|
||||||
|
if actual != a.expected {
|
||||||
|
t.Fatalf("expected %q, got %q", a.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{{$apps := .Applications}}
|
{{$apps := .Applications}}
|
||||||
[backends]{{range .Tasks}}
|
[backends]{{range .Tasks}}
|
||||||
[backends.backend{{.AppID | replace "/" "-"}}.servers.server-{{.ID | replace "." "-"}}]
|
[backends.backend{{with index $apps 0 }}{{getBackend .}}{{end}}.servers.server-{{.ID | replace "." "-"}}]
|
||||||
url = "{{getProtocol . $apps}}://{{.Host}}:{{getPort . $apps}}"
|
url = "{{getProtocol . $apps}}://{{.Host}}:{{getPort . $apps}}"
|
||||||
weight = {{getWeight . $apps}}
|
weight = {{getWeight . $apps}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
[frontends]{{range .Applications}}
|
[frontends]{{range .Applications}}
|
||||||
[frontends.frontend{{.ID | replace "/" "-"}}]
|
[frontends.frontend{{.ID | replace "/" "-"}}]
|
||||||
backend = "backend{{.ID | replace "/" "-"}}"
|
backend = "backend{{getBackend .}}"
|
||||||
passHostHeader = {{getPassHostHeader .}}
|
passHostHeader = {{getPassHostHeader .}}
|
||||||
[frontends.frontend{{.ID | replace "/" "-"}}.routes.route-host{{.ID | replace "/" "-"}}]
|
[frontends.frontend{{.ID | replace "/" "-"}}.routes.route-host{{.ID | replace "/" "-"}}]
|
||||||
rule = "{{getFrontendRule .}}"
|
rule = "{{getFrontendRule .}}"
|
||||||
|
|
Loading…
Reference in a new issue