Fix Docker integration problems

This commit is contained in:
Owen Marshall 2016-06-08 15:08:03 -04:00 committed by Emile Vauge
parent be5b1fd92b
commit c9d4c5ae3e
No known key found for this signature in database
GPG key ID: D808B4C167352E59
3 changed files with 15 additions and 11 deletions

View file

@ -252,6 +252,7 @@ func (provider *Docker) loadDockerConfig(containersInspected []dockerData) *type
"hasMaxConnLabels": provider.hasMaxConnLabels, "hasMaxConnLabels": provider.hasMaxConnLabels,
"getMaxConnAmount": provider.getMaxConnAmount, "getMaxConnAmount": provider.getMaxConnAmount,
"getMaxConnExtractorFunc": provider.getMaxConnExtractorFunc, "getMaxConnExtractorFunc": provider.getMaxConnExtractorFunc,
"getSticky": provider.getSticky,
"replace": replace, "replace": replace,
} }
@ -260,19 +261,26 @@ func (provider *Docker) loadDockerConfig(containersInspected []dockerData) *type
return provider.containerFilter(container) return provider.containerFilter(container)
}, containersInspected).([]dockerData) }, containersInspected).([]dockerData)
// sticky backends
stickycontainers := map[string][]dockerData{}
frontends := map[string][]dockerData{} frontends := map[string][]dockerData{}
for _, container := range filteredContainers { for _, container := range filteredContainers {
frontendName := provider.getFrontendName(container) frontendName := provider.getFrontendName(container)
frontends[frontendName] = append(frontends[frontendName], container) frontends[frontendName] = append(frontends[frontendName], container)
frontends[frontendName] = append(frontends[frontendName], container)
stickycontainers[provider.getBackend(container)] = container
} }
templateObjects := struct { templateObjects := struct {
Containers []dockerData Containers []dockerData
Frontends map[string][]dockerData Frontends map[string][]dockerData
StickyContainers map[string][]dockerData
Domain string Domain string
}{ }{
filteredContainers, filteredContainers,
frontends, frontends,
stickycontainers,
provider.Domain, provider.Domain,
} }
@ -441,9 +449,9 @@ func (provider *Docker) getWeight(container dockerData) string {
func (provider *Docker) getSticky(container dockertypes.ContainerJSON) string { func (provider *Docker) getSticky(container dockertypes.ContainerJSON) string {
if label, err := getLabel(container, "traefik.stickysession"); err == nil { if label, err := getLabel(container, "traefik.stickysession"); err == nil {
return true return "true"
} }
return false return "false"
} }
func (provider *Docker) getDomain(container dockerData) string { func (provider *Docker) getDomain(container dockerData) string {

View file

@ -940,7 +940,7 @@ func TestDockerLoadDockerConfig(t *testing.T) {
}, },
}, },
CircuitBreaker: nil, CircuitBreaker: nil,
LoadBalancer: nil, LoadBalancer: &types.LoadBalancer{Sticky: false, Method: ""},
}, },
}, },
}, },
@ -1027,7 +1027,7 @@ func TestDockerLoadDockerConfig(t *testing.T) {
}, },
}, },
CircuitBreaker: nil, CircuitBreaker: nil,
LoadBalancer: nil, LoadBalancer: &types.LoadBalancer{Sticky: false, Method: ""},
}, },
}, },
}, },

View file

@ -16,10 +16,6 @@
extractorfunc = "{{getMaxConnExtractorFunc . }}" extractorfunc = "{{getMaxConnExtractorFunc . }}"
{{end}} {{end}}
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
url = "{{getProtocol .}}://{{getIPAddress .}}:{{getPort .}}"
weight = {{getWeight .}}
{{end}}
[frontends]{{range $frontend, $containers := .Frontends}} [frontends]{{range $frontend, $containers := .Frontends}}
[frontends."frontend-{{$frontend}}"]{{$container := index $containers 0}} [frontends."frontend-{{$frontend}}"]{{$container := index $containers 0}}