Skip to content

Commit

Permalink
Support traefik.backend for ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
hwhelan-CB authored and traefiker committed Jul 4, 2018
1 parent 04d8b5d commit 12c713b
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 19 deletions.
2 changes: 1 addition & 1 deletion autogen/gentemplates/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions provider/ecs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
func (p *Provider) buildConfigurationV2(instances []ecsInstance) (*types.Configuration, error) {
services := make(map[string][]ecsInstance)
for _, instance := range instances {
backendName := getBackendName(instance)
if p.filterInstance(instance) {
if serviceInstances, ok := services[instance.Name]; ok {
services[instance.Name] = append(serviceInstances, instance)
if serviceInstances, ok := services[backendName]; ok {
services[backendName] = append(serviceInstances, instance)
} else {
services[instance.Name] = []ecsInstance{instance}
services[backendName] = []ecsInstance{instance}
}
}
}
Expand Down Expand Up @@ -98,6 +99,13 @@ func (p *Provider) filterInstance(i ecsInstance) bool {
return true
}

func getBackendName(i ecsInstance) string {
if value := label.GetStringValue(i.TraefikLabels, label.TraefikBackend, ""); len(value) > 0 {
return value
}
return i.Name
}

func (p *Provider) getFrontendRule(i ecsInstance) string {
domain := label.GetStringValue(i.TraefikLabels, label.TraefikDomain, p.Domain)
defaultRule := "Host:" + strings.ToLower(strings.Replace(i.Name, "_", "-", -1)) + "." + domain
Expand All @@ -120,9 +128,10 @@ func filterFrontends(instances []ecsInstance) []ecsInstance {
byName := make(map[string]struct{})

return fun.Filter(func(i ecsInstance) bool {
_, found := byName[i.Name]
backendName := getBackendName(i)
_, found := byName[backendName]
if !found {
byName[i.Name] = struct{}{}
byName[backendName] = struct{}{}
}
return !found
}, instances).([]ecsInstance)
Expand Down
Loading

0 comments on commit 12c713b

Please sign in to comment.