homogenization of templates: Consul Catalog

This commit is contained in:
Ludovic Fernandez 2018-01-10 16:20:10 +01:00 committed by Traefiker
parent 870c0b5cf4
commit 8394549857
3 changed files with 58 additions and 56 deletions

View file

@ -56,34 +56,35 @@ func (fi bindataFileInfo) Sys() interface{} {
var _templatesConsul_catalogTmpl = []byte(`[backends] var _templatesConsul_catalogTmpl = []byte(`[backends]
{{range $service := .Services}} {{range $service := .Services}}
{{ $backendName := getServiceBackendName $service }}
{{ $circuitBreaker := getCircuitBreaker $service.Attributes }} {{ $circuitBreaker := getCircuitBreaker $service.Attributes }}
{{if $circuitBreaker }} {{if $circuitBreaker }}
[backends."backend-{{ getServiceBackendName $service }}".circuitBreaker] [backends."backend-{{ $backendName }}".circuitBreaker]
expression = "{{ $circuitBreaker.Expression }}" expression = "{{ $circuitBreaker.Expression }}"
{{end}} {{end}}
{{ $loadBalancer := getLoadBalancer $service.Attributes }} {{ $loadBalancer := getLoadBalancer $service.Attributes }}
{{if $loadBalancer }} {{if $loadBalancer }}
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer] [backends."backend-{{ $backendName }}".loadBalancer]
method = "{{ $loadBalancer.Method }}" method = "{{ $loadBalancer.Method }}"
sticky = {{ $loadBalancer.Sticky }} sticky = {{ $loadBalancer.Sticky }}
{{if $loadBalancer.Stickiness }} {{if $loadBalancer.Stickiness }}
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer.stickiness] [backends."backend-{{ $backendName }}".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-{{ getServiceBackendName $service }}".maxConn] [backends."backend-{{ $backendName }}".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-{{ getServiceBackendName $service }}.healthCheck] [backends.backend-{{ $backendName }}.healthCheck]
path = "{{ $healthCheck.Path }}" path = "{{ $healthCheck.Path }}"
port = {{ $healthCheck.Port }} port = {{ $healthCheck.Port }}
interval = "{{ $healthCheck.Interval }}" interval = "{{ $healthCheck.Interval }}"
@ -113,7 +114,7 @@ var _templatesConsul_catalogTmpl = []byte(`[backends]
{{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }} {{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }}
{{if $whitelistSourceRange }} {{if $whitelistSourceRange }}
whitelistSourceRange = [{{range $whitelistSourceRange}} whitelistSourceRange = [{{range $whitelistSourceRange }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
@ -130,9 +131,9 @@ var _templatesConsul_catalogTmpl = []byte(`[backends]
replacement = "{{ $redirect.Replacement }}" replacement = "{{ $redirect.Replacement }}"
{{end}} {{end}}
{{ if hasErrorPages $service.Attributes }} {{if hasErrorPages $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".errors] [frontends."frontend-{{ $service.ServiceName }}".errors]
{{ range $pageName, $page := getErrorPages $service.Attributes }} {{range $pageName, $page := getErrorPages $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}] [frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}]
status = [{{range $page.Status }} status = [{{range $page.Status }}
"{{.}}", "{{.}}",
@ -142,13 +143,13 @@ var _templatesConsul_catalogTmpl = []byte(`[backends]
{{end}} {{end}}
{{end}} {{end}}
{{ if hasRateLimit $service.Attributes }} {{if hasRateLimit $service.Attributes }}
{{ $rateLimit := getRateLimit $service.Attributes }} {{ $rateLimit := getRateLimit $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".rateLimit] [frontends."frontend-{{ $service.ServiceName }}".rateLimit]
extractorFunc = "{{ $rateLimit.ExtractorFunc }}" extractorFunc = "{{ $rateLimit.ExtractorFunc }}"
[frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet] [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet]
{{ range $limitName, $limit := $rateLimit.RateSet }} {{range $limitName, $limit := $rateLimit.RateSet }}
[frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}] [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}]
period = "{{ $limit.Period }}" period = "{{ $limit.Period }}"
average = {{ $limit.Average }} average = {{ $limit.Average }}
@ -158,7 +159,7 @@ var _templatesConsul_catalogTmpl = []byte(`[backends]
{{end}} {{end}}
{{ $headers := getHeaders $service.Attributes }} {{ $headers := getHeaders $service.Attributes }}
{{ if $headers }} {{if $headers }}
[frontends."frontend-{{ $service.ServiceName }}".headers] [frontends."frontend-{{ $service.ServiceName }}".headers]
SSLRedirect = {{ $headers.SSLRedirect }} SSLRedirect = {{ $headers.SSLRedirect }}
SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }}
@ -176,33 +177,33 @@ var _templatesConsul_catalogTmpl = []byte(`[backends]
ReferrerPolicy = "{{ $headers.ReferrerPolicy }}" ReferrerPolicy = "{{ $headers.ReferrerPolicy }}"
IsDevelopment = {{ $headers.IsDevelopment }} IsDevelopment = {{ $headers.IsDevelopment }}
{{ if $headers.AllowedHosts }} {{if $headers.AllowedHosts }}
AllowedHosts = [{{ range $headers.AllowedHosts }} AllowedHosts = [{{range $headers.AllowedHosts }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
{{ if $headers.HostsProxyHeaders }} {{if $headers.HostsProxyHeaders }}
HostsProxyHeaders = [{{ range $headers.HostsProxyHeaders }} HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
{{ if $headers.CustomRequestHeaders }} {{if $headers.CustomRequestHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders]
{{ range $k, $v := $headers.CustomRequestHeaders }} {{range $k, $v := $headers.CustomRequestHeaders }}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"
{{end}} {{end}}
{{end}} {{end}}
{{ if $headers.CustomResponseHeaders }} {{if $headers.CustomResponseHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders]
{{ range $k, $v := $headers.CustomResponseHeaders }} {{range $k, $v := $headers.CustomResponseHeaders }}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"
{{end}} {{end}}
{{end}} {{end}}
{{ if $headers.SSLProxyHeaders }} {{if $headers.SSLProxyHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders]
{{range $k, $v := $headers.SSLProxyHeaders}} {{range $k, $v := $headers.SSLProxyHeaders}}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"

View file

@ -24,17 +24,17 @@ func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configurat
"hasTag": hasTag, "hasTag": hasTag,
// Backend functions // Backend functions
"getBackend": getNodeBackendName, // Deprecated [breaking] getBackend -> getNodeBackendName "getBackend": getNodeBackendName, // TODO Deprecated [breaking] getBackend -> getNodeBackendName
"getNodeBackendName": getNodeBackendName, "getNodeBackendName": getNodeBackendName,
"getServiceBackendName": getServiceBackendName, "getServiceBackendName": getServiceBackendName,
"getBackendAddress": getBackendAddress, "getBackendAddress": getBackendAddress,
"getBackendName": getServerName, // Deprecated [breaking] getBackendName -> getServerName "getBackendName": getServerName, // TODO Deprecated [breaking] getBackendName -> getServerName
"getServerName": getServerName, "getServerName": getServerName,
"hasMaxconnAttributes": p.hasMaxConnAttributes, // Deprecated [breaking] "hasMaxconnAttributes": p.hasMaxConnAttributes, // TODO Deprecated [breaking]
"getSticky": p.getSticky, // Deprecated [breaking] "getSticky": p.getSticky, // TODO Deprecated [breaking]
"hasStickinessLabel": p.hasStickinessLabel, // Deprecated [breaking] "hasStickinessLabel": p.hasStickinessLabel, // TODO Deprecated [breaking]
"getStickinessCookieName": p.getStickinessCookieName, // Deprecated [breaking] "getStickinessCookieName": p.getStickinessCookieName, // TODO Deprecated [breaking]
"getWeight": p.getWeight, // Deprecated [breaking] Must replaced by a simple: "getWeight": p.getFuncIntAttribute(label.SuffixWeight, 0) "getWeight": p.getWeight, // TODO Deprecated [breaking] Must replaced by a simple: "getWeight": p.getFuncIntAttribute(label.SuffixWeight, 0)
"getProtocol": p.getFuncStringAttribute(label.SuffixProtocol, label.DefaultProtocol), "getProtocol": p.getFuncStringAttribute(label.SuffixProtocol, label.DefaultProtocol),
"getCircuitBreaker": p.getCircuitBreaker, "getCircuitBreaker": p.getCircuitBreaker,
"getLoadBalancer": p.getLoadBalancer, "getLoadBalancer": p.getLoadBalancer,
@ -44,10 +44,10 @@ func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configurat
// Frontend functions // Frontend functions
"getFrontendRule": p.getFrontendRule, "getFrontendRule": p.getFrontendRule,
"getBasicAuth": p.getFuncSliceAttribute(label.SuffixFrontendAuthBasic), "getBasicAuth": p.getFuncSliceAttribute(label.SuffixFrontendAuthBasic),
"getEntryPoints": getEntryPoints, // Deprecated [breaking] "getEntryPoints": getEntryPoints, // TODO Deprecated [breaking]
"getFrontEndEntryPoints": p.getFuncSliceAttribute(label.SuffixFrontendEntryPoints), // TODO [breaking] rename to getEntryPoints when getEntryPoints will be removed "getFrontEndEntryPoints": p.getFuncSliceAttribute(label.SuffixFrontendEntryPoints), // TODO [breaking] rename to getEntryPoints when getEntryPoints will be removed
"getPriority": p.getFuncIntAttribute(label.SuffixFrontendPriority, 0), "getPriority": p.getFuncIntAttribute(label.SuffixFrontendPriority, label.DefaultFrontendPriorityInt),
"getPassHostHeader": p.getFuncBoolAttribute(label.SuffixFrontendPassHostHeader, true), "getPassHostHeader": p.getFuncBoolAttribute(label.SuffixFrontendPassHostHeader, label.DefaultPassHostHeaderBool),
"getPassTLSCert": p.getFuncBoolAttribute(label.SuffixFrontendPassTLSCert, label.DefaultPassTLSCert), "getPassTLSCert": p.getFuncBoolAttribute(label.SuffixFrontendPassTLSCert, label.DefaultPassTLSCert),
"getWhitelistSourceRange": p.getFuncSliceAttribute(label.SuffixFrontendWhitelistSourceRange), "getWhitelistSourceRange": p.getFuncSliceAttribute(label.SuffixFrontendWhitelistSourceRange),
"getRedirect": p.getRedirect, "getRedirect": p.getRedirect,
@ -201,7 +201,7 @@ func (p *Provider) getStickinessCookieName(tags []string) string {
// Deprecated // Deprecated
func (p *Provider) getWeight(tags []string) int { func (p *Provider) getWeight(tags []string) int {
weight := p.getIntAttribute(label.SuffixWeight, tags, 0) weight := p.getIntAttribute(label.SuffixWeight, tags, label.DefaultWeightInt)
// Deprecated // Deprecated
deprecatedWeightTag := "backend." + label.SuffixWeight deprecatedWeightTag := "backend." + label.SuffixWeight
@ -209,7 +209,7 @@ func (p *Provider) getWeight(tags []string) int {
log.Warnf("Deprecated configuration found: %s. Please use %s.", log.Warnf("Deprecated configuration found: %s. Please use %s.",
p.getPrefixedName(deprecatedWeightTag), p.getPrefixedName(label.SuffixWeight)) p.getPrefixedName(deprecatedWeightTag), p.getPrefixedName(label.SuffixWeight))
weight = p.getIntAttribute(deprecatedWeightTag, tags, 0) weight = p.getIntAttribute(deprecatedWeightTag, tags, label.DefaultWeightInt)
} }
return weight return weight

View file

@ -1,33 +1,34 @@
[backends] [backends]
{{range $service := .Services}} {{range $service := .Services}}
{{ $backendName := getServiceBackendName $service }}
{{ $circuitBreaker := getCircuitBreaker $service.Attributes }} {{ $circuitBreaker := getCircuitBreaker $service.Attributes }}
{{if $circuitBreaker }} {{if $circuitBreaker }}
[backends."backend-{{ getServiceBackendName $service }}".circuitBreaker] [backends."backend-{{ $backendName }}".circuitBreaker]
expression = "{{ $circuitBreaker.Expression }}" expression = "{{ $circuitBreaker.Expression }}"
{{end}} {{end}}
{{ $loadBalancer := getLoadBalancer $service.Attributes }} {{ $loadBalancer := getLoadBalancer $service.Attributes }}
{{if $loadBalancer }} {{if $loadBalancer }}
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer] [backends."backend-{{ $backendName }}".loadBalancer]
method = "{{ $loadBalancer.Method }}" method = "{{ $loadBalancer.Method }}"
sticky = {{ $loadBalancer.Sticky }} sticky = {{ $loadBalancer.Sticky }}
{{if $loadBalancer.Stickiness }} {{if $loadBalancer.Stickiness }}
[backends."backend-{{ getServiceBackendName $service }}".loadBalancer.stickiness] [backends."backend-{{ $backendName }}".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-{{ getServiceBackendName $service }}".maxConn] [backends."backend-{{ $backendName }}".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-{{ getServiceBackendName $service }}.healthCheck] [backends.backend-{{ $backendName }}.healthCheck]
path = "{{ $healthCheck.Path }}" path = "{{ $healthCheck.Path }}"
port = {{ $healthCheck.Port }} port = {{ $healthCheck.Port }}
interval = "{{ $healthCheck.Interval }}" interval = "{{ $healthCheck.Interval }}"
@ -57,7 +58,7 @@
{{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }} {{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }}
{{if $whitelistSourceRange }} {{if $whitelistSourceRange }}
whitelistSourceRange = [{{range $whitelistSourceRange}} whitelistSourceRange = [{{range $whitelistSourceRange }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
@ -74,9 +75,9 @@
replacement = "{{ $redirect.Replacement }}" replacement = "{{ $redirect.Replacement }}"
{{end}} {{end}}
{{ if hasErrorPages $service.Attributes }} {{if hasErrorPages $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".errors] [frontends."frontend-{{ $service.ServiceName }}".errors]
{{ range $pageName, $page := getErrorPages $service.Attributes }} {{range $pageName, $page := getErrorPages $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}] [frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}]
status = [{{range $page.Status }} status = [{{range $page.Status }}
"{{.}}", "{{.}}",
@ -86,13 +87,13 @@
{{end}} {{end}}
{{end}} {{end}}
{{ if hasRateLimit $service.Attributes }} {{if hasRateLimit $service.Attributes }}
{{ $rateLimit := getRateLimit $service.Attributes }} {{ $rateLimit := getRateLimit $service.Attributes }}
[frontends."frontend-{{ $service.ServiceName }}".rateLimit] [frontends."frontend-{{ $service.ServiceName }}".rateLimit]
extractorFunc = "{{ $rateLimit.ExtractorFunc }}" extractorFunc = "{{ $rateLimit.ExtractorFunc }}"
[frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet] [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet]
{{ range $limitName, $limit := $rateLimit.RateSet }} {{range $limitName, $limit := $rateLimit.RateSet }}
[frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}] [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}]
period = "{{ $limit.Period }}" period = "{{ $limit.Period }}"
average = {{ $limit.Average }} average = {{ $limit.Average }}
@ -102,7 +103,7 @@
{{end}} {{end}}
{{ $headers := getHeaders $service.Attributes }} {{ $headers := getHeaders $service.Attributes }}
{{ if $headers }} {{if $headers }}
[frontends."frontend-{{ $service.ServiceName }}".headers] [frontends."frontend-{{ $service.ServiceName }}".headers]
SSLRedirect = {{ $headers.SSLRedirect }} SSLRedirect = {{ $headers.SSLRedirect }}
SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }}
@ -120,33 +121,33 @@
ReferrerPolicy = "{{ $headers.ReferrerPolicy }}" ReferrerPolicy = "{{ $headers.ReferrerPolicy }}"
IsDevelopment = {{ $headers.IsDevelopment }} IsDevelopment = {{ $headers.IsDevelopment }}
{{ if $headers.AllowedHosts }} {{if $headers.AllowedHosts }}
AllowedHosts = [{{ range $headers.AllowedHosts }} AllowedHosts = [{{range $headers.AllowedHosts }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
{{ if $headers.HostsProxyHeaders }} {{if $headers.HostsProxyHeaders }}
HostsProxyHeaders = [{{ range $headers.HostsProxyHeaders }} HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }}
"{{.}}", "{{.}}",
{{end}}] {{end}}]
{{end}} {{end}}
{{ if $headers.CustomRequestHeaders }} {{if $headers.CustomRequestHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders]
{{ range $k, $v := $headers.CustomRequestHeaders }} {{range $k, $v := $headers.CustomRequestHeaders }}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"
{{end}} {{end}}
{{end}} {{end}}
{{ if $headers.CustomResponseHeaders }} {{if $headers.CustomResponseHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders]
{{ range $k, $v := $headers.CustomResponseHeaders }} {{range $k, $v := $headers.CustomResponseHeaders }}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"
{{end}} {{end}}
{{end}} {{end}}
{{ if $headers.SSLProxyHeaders }} {{if $headers.SSLProxyHeaders }}
[frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders] [frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders]
{{range $k, $v := $headers.SSLProxyHeaders}} {{range $k, $v := $headers.SSLProxyHeaders}}
{{$k}} = "{{$v}}" {{$k}} = "{{$v}}"