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, "hasTag": hasTag,
// Backend functions // Backend functions
"getBackend": getBackend, "getBackend": getNodeBackendName, // Deprecated [breaking] getBackend -> getNodeBackendName
"getNodeBackendName": getNodeBackendName,
"getServiceBackendName": getServiceBackendName,
"getBackendAddress": getBackendAddress, "getBackendAddress": getBackendAddress,
"getBackendName": getServerName, // Deprecated [breaking] getBackendName -> getServerName "getBackendName": getServerName, // Deprecated [breaking] getBackendName -> getServerName
"getServerName": getServerName, "getServerName": getServerName,
@ -139,10 +141,14 @@ func getEntryPoints(list string) []string {
return strings.Split(list, ",") return strings.Split(list, ",")
} }
func getBackend(node *api.ServiceEntry) string { func getNodeBackendName(node *api.ServiceEntry) string {
return strings.ToLower(node.Service.Service) return strings.ToLower(node.Service.Service)
} }
func getServiceBackendName(service *serviceUpdate) string {
return strings.ToLower(service.ServiceName)
}
func getBackendAddress(node *api.ServiceEntry) string { func getBackendAddress(node *api.ServiceEntry) string {
if node.Service.Address != "" { if node.Service.Address != "" {
return node.Service.Address return node.Service.Address

View file

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