Support traefik.backend
for ECS
This commit is contained in:
parent
04d8b5d483
commit
12c713b187
6 changed files with 491 additions and 19 deletions
|
@ -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}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue