diff --git a/provider/ecs/config.go b/provider/ecs/config.go index 8bb1aa234..df28c315d 100644 --- a/provider/ecs/config.go +++ b/provider/ecs/config.go @@ -17,6 +17,7 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types "filterFrontends": filterFrontends, "getFrontendRule": p.getFrontendRule, "getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic), + "hasLoadBalancerLabel": hasLoadBalancerLabel, "getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod), "getSticky": getSticky, "hasStickinessLabel": getFuncFirstBoolValue(label.TraefikBackendLoadBalancerStickiness, false), @@ -77,6 +78,15 @@ func filterFrontends(instances []ecsInstance) []ecsInstance { }, instances).([]ecsInstance) } +func hasLoadBalancerLabel(instances []ecsInstance) bool { + method := hasFirst(instances, label.TraefikBackendLoadBalancerMethod) + sticky := hasFirst(instances, label.TraefikBackendLoadBalancerSticky) + stickiness := hasFirst(instances, label.TraefikBackendLoadBalancerStickiness) + cookieName := hasFirst(instances, label.TraefikBackendLoadBalancerStickinessCookieName) + + return method || sticky || stickiness || cookieName +} + // Label functions func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string { diff --git a/provider/ecs/config_test.go b/provider/ecs/config_test.go index da663c553..24d14c5d8 100644 --- a/provider/ecs/config_test.go +++ b/provider/ecs/config_test.go @@ -105,9 +105,6 @@ func TestBuildConfiguration(t *testing.T) { }, }, "backend-testing": { - LoadBalancer: &types.LoadBalancer{ - Method: "wrr", - }, HealthCheck: &types.HealthCheck{ Path: "/health", Interval: "1s", diff --git a/templates/ecs.tmpl b/templates/ecs.tmpl index 7bf03b3de..371046b8c 100644 --- a/templates/ecs.tmpl +++ b/templates/ecs.tmpl @@ -1,6 +1,7 @@ [backends] {{range $serviceName, $instances := .Services}} + {{if hasLoadBalancerLabel $instances}} [backends.backend-{{ $serviceName }}.loadBalancer] method = "{{ getLoadBalancerMethod $instances}}" sticky = {{ getSticky $instances}} @@ -8,6 +9,7 @@ [backends.backend-{{ $serviceName }}.loadBalancer.stickiness] cookieName = "{{getStickinessCookieName $instances}}" {{end}} + {{end}} {{ if hasHealthCheckLabels $instances }} [backends.backend-{{ $serviceName }}.healthCheck]