refactor: add backend name functions.

This commit is contained in:
Fernandez Ludovic 2018-01-02 18:21:38 +01:00 committed by Traefiker
parent e56551d047
commit 8e7ac513b6
2 changed files with 16 additions and 11 deletions

View file

@ -24,7 +24,9 @@ func (p *CatalogProvider) buildConfiguration(catalog []catalogUpdate) *types.Con
"hasTag": hasTag,
// Backend functions
"getBackend": getBackend,
"getBackend": getNodeBackendName, // Deprecated [breaking] getBackend -> getNodeBackendName
"getNodeBackendName": getNodeBackendName,
"getServiceBackendName": getServiceBackendName,
"getBackendAddress": getBackendAddress,
"getBackendName": getServerName, // Deprecated [breaking] getBackendName -> getServerName
"getServerName": getServerName,
@ -139,10 +141,14 @@ func getEntryPoints(list string) []string {
return strings.Split(list, ",")
}
func getBackend(node *api.ServiceEntry) string {
func getNodeBackendName(node *api.ServiceEntry) string {
return strings.ToLower(node.Service.Service)
}
func getServiceBackendName(service *serviceUpdate) string {
return strings.ToLower(service.ServiceName)
}
func getBackendAddress(node *api.ServiceEntry) string {
if node.Service.Address != "" {
return node.Service.Address

View file

@ -1,34 +1,33 @@
[backends]
{{range $service := .Services}}
{{$sname := $service.ServiceName}}
{{ $circuitBreaker := getCircuitBreaker $service.Attributes }}
{{if $circuitBreaker }}
[backends."backend-{{ $sname }}".circuitBreaker]
[backends."backend-{{ getServiceBackendName $service }}".circuitBreaker]
expression = "{{ $circuitBreaker.Expression }}"
{{end}}
{{ $loadBalancer := getLoadBalancer $service.Attributes }}
{{if $loadBalancer }}
[backends."backend-{{ $sname }}".loadBalancer]
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer]
method = "{{ $loadBalancer.Method }}"
sticky = {{ $loadBalancer.Sticky }}
{{if $loadBalancer.Stickiness }}
[backends."backend-{{ $sname }}".loadBalancer.stickiness]
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer.stickiness]
cookieName = "{{ $loadBalancer.Stickiness.CookieName }}"
{{end}}
{{end}}
{{ $maxConn := getMaxConn $service.Attributes }}
{{if $maxConn }}
[backends."backend-{{ $sname }}".maxConn]
[backends."backend-{{ getServiceBackendName $service }}".maxConn]
extractorFunc = "{{ $maxConn.ExtractorFunc }}"
amount = {{ $maxConn.Amount }}
{{end}}
{{ $healthCheck := getHealthCheck $service.Attributes }}
{{if $healthCheck }}
[backends.backend-{{ $sname }}.healthCheck]
[backends.backend-{{ getServiceBackendName $service }}.healthCheck]
path = "{{ $healthCheck.Path }}"
port = {{ $healthCheck.Port }}
interval = "{{ $healthCheck.Interval }}"
@ -37,7 +36,7 @@
{{end}}
{{range $index, $node := .Nodes}}
[backends."backend-{{ getBackend $node }}".servers."{{ getServerName $node $index }}"]
[backends."backend-{{ getNodeBackendName $node }}".servers."{{ getServerName $node $index }}"]
url = "{{ getProtocol $node.Service.Tags }}://{{ getBackendAddress $node }}:{{ $node.Service.Port }}"
weight = {{ getWeight $node.Service.Tags }}
@ -47,7 +46,7 @@
{{range $service := .Services}}
[frontends."frontend-{{ $service.ServiceName }}"]
backend = "backend-{{ $service.ServiceName }}"
backend = "backend-{{ getServiceBackendName $service }}"
priority = {{ getPriority $service.Attributes }}
passHostHeader = {{ getPassHostHeader $service.Attributes }}
passTLSCert = {{ getPassTLSCert $service.Attributes }}
@ -102,7 +101,7 @@
{{end}}
[frontends."frontend-{{$service.ServiceName}}".routes."route-host-{{$service.ServiceName}}"]
[frontends."frontend-{{ $service.ServiceName }}".routes."route-host-{{ $service.ServiceName }}"]
rule = "{{ getFrontendRule $service }}"
{{end}}