Merge pull request #195 from emilevauge/fix-regression-marathon-backends

Fix regression on marathon backend
This commit is contained in:
Vincent Demeester 2016-02-12 15:31:59 +01:00
commit e9c23195a0
4 changed files with 25 additions and 14 deletions

View file

@ -81,16 +81,17 @@ 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, "getBackend": provider.getBackend,
"getPort": provider.getPort, "getPort": provider.getPort,
"getWeight": provider.getWeight, "getWeight": provider.getWeight,
"getDomain": provider.getDomain, "getDomain": provider.getDomain,
"getProtocol": provider.getProtocol, "getProtocol": provider.getProtocol,
"getPassHostHeader": provider.getPassHostHeader, "getPassHostHeader": provider.getPassHostHeader,
"getEntryPoints": provider.getEntryPoints, "getEntryPoints": provider.getEntryPoints,
"getFrontendValue": provider.getFrontendValue, "getFrontendValue": provider.getFrontendValue,
"getFrontendRule": provider.getFrontendRule, "getFrontendRule": provider.getFrontendRule,
"replace": replace, "getFrontendBackend": provider.getFrontendBackend,
"replace": replace,
} }
applications, err := provider.marathonClient.Applications(nil) applications, err := provider.marathonClient.Applications(nil)
@ -313,7 +314,16 @@ func (provider *Marathon) getFrontendRule(application marathon.Application) stri
return "Host" return "Host"
} }
func (provider *Marathon) getBackend(application marathon.Application) string { func (provider *Marathon) getBackend(task marathon.Task, applications []marathon.Application) string {
application, errApp := getApplication(task, applications)
if errApp != nil {
log.Errorf("Unable to get marathon application from task %s", task.AppID)
return ""
}
return provider.getFrontendBackend(application)
}
func (provider *Marathon) getFrontendBackend(application marathon.Application) string {
if label, err := provider.getLabel(application, "traefik.backend"); err == nil { if label, err := provider.getLabel(application, "traefik.backend"); err == nil {
return label return label
} }

View file

@ -851,7 +851,7 @@ func TestMarathonGetBackend(t *testing.T) {
} }
for _, a := range applications { for _, a := range applications {
actual := provider.getBackend(a.application) actual := provider.getFrontendBackend(a.application)
if actual != a.expected { if actual != a.expected {
t.Fatalf("expected %q, got %q", a.expected, actual) t.Fatalf("expected %q, got %q", a.expected, actual)
} }

View file

@ -1,13 +1,13 @@
{{$apps := .Applications}} {{$apps := .Applications}}
[backends]{{range .Tasks}} [backends]{{range .Tasks}}
[backends.backend{{with index $apps 0 }}{{getBackend .}}{{end}}.servers.server-{{.ID | replace "." "-"}}] [backends.backend{{getBackend . $apps}}.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{{getBackend .}}" backend = "backend{{getFrontendBackend .}}"
passHostHeader = {{getPassHostHeader .}} passHostHeader = {{getPassHostHeader .}}
entryPoints = [{{range getEntryPoints .}} entryPoints = [{{range getEntryPoints .}}
"{{.}}", "{{.}}",

View file

@ -31,6 +31,7 @@ slave:
- /usr/bin/docker:/usr/bin/docker:ro - /usr/bin/docker:/usr/bin/docker:ro
- /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1:ro - /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1:ro
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- /lib/x86_64-linux-gnu/libsystemd-journal.so.0:/lib/x86_64-linux-gnu/libsystemd-journal.so.0
marathon: marathon:
image: mesosphere/marathon:v0.13.0 image: mesosphere/marathon:v0.13.0