refactor(consulcatalog): template readability.

This commit is contained in:
Fernandez Ludovic 2017-12-31 23:49:32 +01:00 committed by Traefiker
parent de7dd068d9
commit 6e23454202

View file

@ -1,52 +1,56 @@
[backends] [backends]
{{range $index, $node := .Nodes}} {{range $service := .Services}}
[backends."backend-{{getBackend $node}}".servers."{{getBackendName $node $index}}"] {{$sname := $service.ServiceName}}
url = "{{getAttribute "protocol" $node.Service.Tags "http"}}://{{getBackendAddress $node}}:{{$node.Service.Port}}"
{{$weight := getAttribute "backend.weight" $node.Service.Tags "0"}}
{{with $weight}}
weight = {{$weight}}
{{end}}
{{end}}
{{range .Services}} {{$circuitBreaker := getAttribute "backend.circuitbreaker" $service.Attributes ""}}
{{$service := .ServiceName}}
{{$circuitBreaker := getAttribute "backend.circuitbreaker" .Attributes ""}}
{{with $circuitBreaker}} {{with $circuitBreaker}}
[backends."backend-{{$service}}".circuitbreaker] [backends."backend-{{$sname}}".circuitBreaker]
expression = "{{$circuitBreaker}}" expression = "{{$circuitBreaker}}"
{{end}} {{end}}
[backends."backend-{{$service}}".loadbalancer] [backends."backend-{{$sname}}".loadBalancer]
method = "{{getAttribute "backend.loadbalancer" .Attributes "wrr"}}" method = "{{getAttribute "backend.loadbalancer" $service.Attributes "wrr"}}"
sticky = {{getSticky .Attributes}} sticky = {{getSticky $service.Attributes}}
{{if hasStickinessLabel .Attributes}} {{if hasStickinessLabel $service.Attributes}}
[backends."backend-{{$service}}".loadbalancer.stickiness] [backends."backend-{{$sname}}".loadBalancer.stickiness]
cookieName = "{{getStickinessCookieName .Attributes}}" cookieName = "{{getStickinessCookieName $service.Attributes}}"
{{end}} {{end}}
{{if hasMaxconnAttributes .Attributes}} {{if hasMaxconnAttributes $service.Attributes}}
[backends."backend-{{$service}}".maxconn] [backends."backend-{{$sname}}".maxConn]
amount = {{getAttribute "backend.maxconn.amount" .Attributes "" }} amount = {{getAttribute "backend.maxconn.amount" $service.Attributes "" }}
extractorfunc = "{{getAttribute "backend.maxconn.extractorfunc" .Attributes "" }}" extractorFunc = "{{getAttribute "backend.maxconn.extractorfunc" $service.Attributes "" }}"
{{end}} {{end}}
{{end}}
{{range $index, $node := .Nodes}}
[backends."backend-{{getBackend $node}}".servers."{{getBackendName $node $index}}"]
url = "{{getAttribute "protocol" $node.Service.Tags "http"}}://{{getBackendAddress $node}}:{{$node.Service.Port}}"
weight = {{ getAttribute "backend.weight" $node.Service.Tags "0" }}
{{end}} {{end}}
[frontends] [frontends]
{{range .Services}} {{range $service := .Services}}
[frontends."frontend-{{.ServiceName}}"]
backend = "backend-{{.ServiceName}}" [frontends."frontend-{{$service.ServiceName}}"]
passHostHeader = {{getAttribute "frontend.passHostHeader" .Attributes "true"}} backend = "backend-{{$service.ServiceName}}"
priority = {{getAttribute "frontend.priority" .Attributes "0"}} priority = {{getAttribute "frontend.priority" $service.Attributes "0"}}
{{$entryPoints := getAttribute "frontend.entrypoints" .Attributes ""}} passHostHeader = {{getAttribute "frontend.passHostHeader" $service.Attributes "true"}}
{{$entryPoints := getAttribute "frontend.entrypoints" $service.Attributes ""}}
{{with $entryPoints}} {{with $entryPoints}}
entrypoints = [{{range getEntryPoints $entryPoints}} entryPoints = [{{range getEntryPoints $entryPoints}}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
basicAuth = [{{range getBasicAuth .Attributes}}
basicAuth = [{{range getBasicAuth $service.Attributes}}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
[frontends."frontend-{{.ServiceName}}".routes."route-host-{{.ServiceName}}"]
rule = "{{getFrontendRule .}}" [frontends."frontend-{{$service.ServiceName}}".routes."route-host-{{$service.ServiceName}}"]
rule = "{{getFrontendRule $service}}"
{{end}} {{end}}