refactor(ecs): add hasLoadBalancerLabel function.
This commit is contained in:
parent
722ea28e3a
commit
07a6d48a27
3 changed files with 12 additions and 3 deletions
|
@ -17,6 +17,7 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types
|
||||||
"filterFrontends": filterFrontends,
|
"filterFrontends": filterFrontends,
|
||||||
"getFrontendRule": p.getFrontendRule,
|
"getFrontendRule": p.getFrontendRule,
|
||||||
"getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic),
|
"getBasicAuth": getFuncSliceString(label.TraefikFrontendAuthBasic),
|
||||||
|
"hasLoadBalancerLabel": hasLoadBalancerLabel,
|
||||||
"getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod),
|
"getLoadBalancerMethod": getFuncFirstStringValue(label.TraefikBackendLoadBalancerMethod, label.DefaultBackendLoadBalancerMethod),
|
||||||
"getSticky": getSticky,
|
"getSticky": getSticky,
|
||||||
"hasStickinessLabel": getFuncFirstBoolValue(label.TraefikBackendLoadBalancerStickiness, false),
|
"hasStickinessLabel": getFuncFirstBoolValue(label.TraefikBackendLoadBalancerStickiness, false),
|
||||||
|
@ -77,6 +78,15 @@ func filterFrontends(instances []ecsInstance) []ecsInstance {
|
||||||
}, instances).([]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
|
// Label functions
|
||||||
|
|
||||||
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
||||||
|
|
|
@ -105,9 +105,6 @@ func TestBuildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"backend-testing": {
|
"backend-testing": {
|
||||||
LoadBalancer: &types.LoadBalancer{
|
|
||||||
Method: "wrr",
|
|
||||||
},
|
|
||||||
HealthCheck: &types.HealthCheck{
|
HealthCheck: &types.HealthCheck{
|
||||||
Path: "/health",
|
Path: "/health",
|
||||||
Interval: "1s",
|
Interval: "1s",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[backends]
|
[backends]
|
||||||
{{range $serviceName, $instances := .Services}}
|
{{range $serviceName, $instances := .Services}}
|
||||||
|
|
||||||
|
{{if hasLoadBalancerLabel $instances}}
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer]
|
[backends.backend-{{ $serviceName }}.loadBalancer]
|
||||||
method = "{{ getLoadBalancerMethod $instances}}"
|
method = "{{ getLoadBalancerMethod $instances}}"
|
||||||
sticky = {{ getSticky $instances}}
|
sticky = {{ getSticky $instances}}
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
[backends.backend-{{ $serviceName }}.loadBalancer.stickiness]
|
[backends.backend-{{ $serviceName }}.loadBalancer.stickiness]
|
||||||
cookieName = "{{getStickinessCookieName $instances}}"
|
cookieName = "{{getStickinessCookieName $instances}}"
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{ if hasHealthCheckLabels $instances }}
|
{{ if hasHealthCheckLabels $instances }}
|
||||||
[backends.backend-{{ $serviceName }}.healthCheck]
|
[backends.backend-{{ $serviceName }}.healthCheck]
|
||||||
|
|
Loading…
Reference in a new issue