refactor(ecs): add hasLoadBalancerLabel function.

This commit is contained in:
Fernandez Ludovic 2017-12-16 19:38:12 +01:00 committed by Traefiker
parent 722ea28e3a
commit 07a6d48a27
3 changed files with 12 additions and 3 deletions

View file

@ -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 {

View file

@ -105,9 +105,6 @@ func TestBuildConfiguration(t *testing.T) {
},
},
"backend-testing": {
LoadBalancer: &types.LoadBalancer{
Method: "wrr",
},
HealthCheck: &types.HealthCheck{
Path: "/health",
Interval: "1s",

View file

@ -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]