diff --git a/autogen/gentemplates/gen.go b/autogen/gentemplates/gen.go index e64ad0d94..e4b53f14e 100644 --- a/autogen/gentemplates/gen.go +++ b/autogen/gentemplates/gen.go @@ -56,34 +56,35 @@ func (fi bindataFileInfo) Sys() interface{} { var _templatesConsul_catalogTmpl = []byte(`[backends] {{range $service := .Services}} + {{ $backendName := getServiceBackendName $service }} {{ $circuitBreaker := getCircuitBreaker $service.Attributes }} {{if $circuitBreaker }} - [backends."backend-{{ getServiceBackendName $service }}".circuitBreaker] + [backends."backend-{{ $backendName }}".circuitBreaker] expression = "{{ $circuitBreaker.Expression }}" {{end}} {{ $loadBalancer := getLoadBalancer $service.Attributes }} {{if $loadBalancer }} - [backends."backend-{{ getServiceBackendName $service }}".loadBalancer] + [backends."backend-{{ $backendName }}".loadBalancer] method = "{{ $loadBalancer.Method }}" sticky = {{ $loadBalancer.Sticky }} {{if $loadBalancer.Stickiness }} - [backends."backend-{{ getServiceBackendName $service }}".loadBalancer.stickiness] + [backends."backend-{{ $backendName }}".loadBalancer.stickiness] cookieName = "{{ $loadBalancer.Stickiness.CookieName }}" {{end}} {{end}} {{ $maxConn := getMaxConn $service.Attributes }} {{if $maxConn }} - [backends."backend-{{ getServiceBackendName $service }}".maxConn] + [backends."backend-{{ $backendName }}".maxConn] extractorFunc = "{{ $maxConn.ExtractorFunc }}" amount = {{ $maxConn.Amount }} {{end}} {{ $healthCheck := getHealthCheck $service.Attributes }} {{if $healthCheck }} - [backends.backend-{{ getServiceBackendName $service }}.healthCheck] + [backends.backend-{{ $backendName }}.healthCheck] path = "{{ $healthCheck.Path }}" port = {{ $healthCheck.Port }} interval = "{{ $healthCheck.Interval }}" @@ -113,7 +114,7 @@ var _templatesConsul_catalogTmpl = []byte(`[backends] {{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }} {{if $whitelistSourceRange }} - whitelistSourceRange = [{{range $whitelistSourceRange}} + whitelistSourceRange = [{{range $whitelistSourceRange }} "{{.}}", {{end}}] {{end}} @@ -130,25 +131,25 @@ var _templatesConsul_catalogTmpl = []byte(`[backends] replacement = "{{ $redirect.Replacement }}" {{end}} - {{ if hasErrorPages $service.Attributes }} + {{if hasErrorPages $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".errors] - {{ range $pageName, $page := getErrorPages $service.Attributes }} + {{range $pageName, $page := getErrorPages $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}] status = [{{range $page.Status }} - "{{.}}", - {{end}}] + "{{.}}", + {{end}}] backend = "{{ $page.Backend }}" query = "{{ $page.Query }}" {{end}} {{end}} - {{ if hasRateLimit $service.Attributes }} + {{if hasRateLimit $service.Attributes }} {{ $rateLimit := getRateLimit $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".rateLimit] extractorFunc = "{{ $rateLimit.ExtractorFunc }}" [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet] - {{ range $limitName, $limit := $rateLimit.RateSet }} + {{range $limitName, $limit := $rateLimit.RateSet }} [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}] period = "{{ $limit.Period }}" average = {{ $limit.Average }} @@ -158,7 +159,7 @@ var _templatesConsul_catalogTmpl = []byte(`[backends] {{end}} {{ $headers := getHeaders $service.Attributes }} - {{ if $headers }} + {{if $headers }} [frontends."frontend-{{ $service.ServiceName }}".headers] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} @@ -176,33 +177,33 @@ var _templatesConsul_catalogTmpl = []byte(`[backends] ReferrerPolicy = "{{ $headers.ReferrerPolicy }}" IsDevelopment = {{ $headers.IsDevelopment }} - {{ if $headers.AllowedHosts }} - AllowedHosts = [{{ range $headers.AllowedHosts }} + {{if $headers.AllowedHosts }} + AllowedHosts = [{{range $headers.AllowedHosts }} "{{.}}", {{end}}] {{end}} - {{ if $headers.HostsProxyHeaders }} - HostsProxyHeaders = [{{ range $headers.HostsProxyHeaders }} + {{if $headers.HostsProxyHeaders }} + HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }} "{{.}}", {{end}}] {{end}} - {{ if $headers.CustomRequestHeaders }} + {{if $headers.CustomRequestHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders] - {{ range $k, $v := $headers.CustomRequestHeaders }} + {{range $k, $v := $headers.CustomRequestHeaders }} {{$k}} = "{{$v}}" {{end}} {{end}} - {{ if $headers.CustomResponseHeaders }} + {{if $headers.CustomResponseHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders] - {{ range $k, $v := $headers.CustomResponseHeaders }} + {{range $k, $v := $headers.CustomResponseHeaders }} {{$k}} = "{{$v}}" {{end}} {{end}} - {{ if $headers.SSLProxyHeaders }} + {{if $headers.SSLProxyHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders] {{range $k, $v := $headers.SSLProxyHeaders}} {{$k}} = "{{$v}}" diff --git a/provider/consulcatalog/consul_catalog_config.go b/provider/consulcatalog/consul_catalog_config.go index c718885cf..a096e664b 100644 --- a/provider/consulcatalog/consul_catalog_config.go +++ b/provider/consulcatalog/consul_catalog_config.go @@ -24,17 +24,17 @@ func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configurat "hasTag": hasTag, // Backend functions - "getBackend": getNodeBackendName, // Deprecated [breaking] getBackend -> getNodeBackendName + "getBackend": getNodeBackendName, // TODO Deprecated [breaking] getBackend -> getNodeBackendName "getNodeBackendName": getNodeBackendName, "getServiceBackendName": getServiceBackendName, "getBackendAddress": getBackendAddress, - "getBackendName": getServerName, // Deprecated [breaking] getBackendName -> getServerName + "getBackendName": getServerName, // TODO Deprecated [breaking] getBackendName -> getServerName "getServerName": getServerName, - "hasMaxconnAttributes": p.hasMaxConnAttributes, // Deprecated [breaking] - "getSticky": p.getSticky, // Deprecated [breaking] - "hasStickinessLabel": p.hasStickinessLabel, // Deprecated [breaking] - "getStickinessCookieName": p.getStickinessCookieName, // Deprecated [breaking] - "getWeight": p.getWeight, // Deprecated [breaking] Must replaced by a simple: "getWeight": p.getFuncIntAttribute(label.SuffixWeight, 0) + "hasMaxconnAttributes": p.hasMaxConnAttributes, // TODO Deprecated [breaking] + "getSticky": p.getSticky, // TODO Deprecated [breaking] + "hasStickinessLabel": p.hasStickinessLabel, // TODO Deprecated [breaking] + "getStickinessCookieName": p.getStickinessCookieName, // TODO Deprecated [breaking] + "getWeight": p.getWeight, // TODO Deprecated [breaking] Must replaced by a simple: "getWeight": p.getFuncIntAttribute(label.SuffixWeight, 0) "getProtocol": p.getFuncStringAttribute(label.SuffixProtocol, label.DefaultProtocol), "getCircuitBreaker": p.getCircuitBreaker, "getLoadBalancer": p.getLoadBalancer, @@ -44,10 +44,10 @@ func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configurat // Frontend functions "getFrontendRule": p.getFrontendRule, "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 - "getPriority": p.getFuncIntAttribute(label.SuffixFrontendPriority, 0), - "getPassHostHeader": p.getFuncBoolAttribute(label.SuffixFrontendPassHostHeader, true), + "getPriority": p.getFuncIntAttribute(label.SuffixFrontendPriority, label.DefaultFrontendPriorityInt), + "getPassHostHeader": p.getFuncBoolAttribute(label.SuffixFrontendPassHostHeader, label.DefaultPassHostHeaderBool), "getPassTLSCert": p.getFuncBoolAttribute(label.SuffixFrontendPassTLSCert, label.DefaultPassTLSCert), "getWhitelistSourceRange": p.getFuncSliceAttribute(label.SuffixFrontendWhitelistSourceRange), "getRedirect": p.getRedirect, @@ -201,7 +201,7 @@ func (p *Provider) getStickinessCookieName(tags []string) string { // Deprecated func (p *Provider) getWeight(tags []string) int { - weight := p.getIntAttribute(label.SuffixWeight, tags, 0) + weight := p.getIntAttribute(label.SuffixWeight, tags, label.DefaultWeightInt) // Deprecated deprecatedWeightTag := "backend." + label.SuffixWeight @@ -209,7 +209,7 @@ func (p *Provider) getWeight(tags []string) int { log.Warnf("Deprecated configuration found: %s. Please use %s.", p.getPrefixedName(deprecatedWeightTag), p.getPrefixedName(label.SuffixWeight)) - weight = p.getIntAttribute(deprecatedWeightTag, tags, 0) + weight = p.getIntAttribute(deprecatedWeightTag, tags, label.DefaultWeightInt) } return weight diff --git a/templates/consul_catalog.tmpl b/templates/consul_catalog.tmpl index 7c8317725..e0bb1cd08 100644 --- a/templates/consul_catalog.tmpl +++ b/templates/consul_catalog.tmpl @@ -1,33 +1,34 @@ [backends] {{range $service := .Services}} + {{ $backendName := getServiceBackendName $service }} {{ $circuitBreaker := getCircuitBreaker $service.Attributes }} {{if $circuitBreaker }} - [backends."backend-{{ getServiceBackendName $service }}".circuitBreaker] + [backends."backend-{{ $backendName }}".circuitBreaker] expression = "{{ $circuitBreaker.Expression }}" {{end}} {{ $loadBalancer := getLoadBalancer $service.Attributes }} {{if $loadBalancer }} - [backends."backend-{{ getServiceBackendName $service }}".loadBalancer] + [backends."backend-{{ $backendName }}".loadBalancer] method = "{{ $loadBalancer.Method }}" sticky = {{ $loadBalancer.Sticky }} {{if $loadBalancer.Stickiness }} - [backends."backend-{{ getServiceBackendName $service }}".loadBalancer.stickiness] + [backends."backend-{{ $backendName }}".loadBalancer.stickiness] cookieName = "{{ $loadBalancer.Stickiness.CookieName }}" {{end}} {{end}} {{ $maxConn := getMaxConn $service.Attributes }} {{if $maxConn }} - [backends."backend-{{ getServiceBackendName $service }}".maxConn] + [backends."backend-{{ $backendName }}".maxConn] extractorFunc = "{{ $maxConn.ExtractorFunc }}" amount = {{ $maxConn.Amount }} {{end}} {{ $healthCheck := getHealthCheck $service.Attributes }} {{if $healthCheck }} - [backends.backend-{{ getServiceBackendName $service }}.healthCheck] + [backends.backend-{{ $backendName }}.healthCheck] path = "{{ $healthCheck.Path }}" port = {{ $healthCheck.Port }} interval = "{{ $healthCheck.Interval }}" @@ -57,7 +58,7 @@ {{ $whitelistSourceRange := getWhitelistSourceRange $service.Attributes }} {{if $whitelistSourceRange }} - whitelistSourceRange = [{{range $whitelistSourceRange}} + whitelistSourceRange = [{{range $whitelistSourceRange }} "{{.}}", {{end}}] {{end}} @@ -74,25 +75,25 @@ replacement = "{{ $redirect.Replacement }}" {{end}} - {{ if hasErrorPages $service.Attributes }} + {{if hasErrorPages $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".errors] - {{ range $pageName, $page := getErrorPages $service.Attributes }} + {{range $pageName, $page := getErrorPages $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".errors.{{ $pageName }}] status = [{{range $page.Status }} - "{{.}}", - {{end}}] + "{{.}}", + {{end}}] backend = "{{ $page.Backend }}" query = "{{ $page.Query }}" {{end}} {{end}} - {{ if hasRateLimit $service.Attributes }} + {{if hasRateLimit $service.Attributes }} {{ $rateLimit := getRateLimit $service.Attributes }} [frontends."frontend-{{ $service.ServiceName }}".rateLimit] extractorFunc = "{{ $rateLimit.ExtractorFunc }}" [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet] - {{ range $limitName, $limit := $rateLimit.RateSet }} + {{range $limitName, $limit := $rateLimit.RateSet }} [frontends."frontend-{{ $service.ServiceName }}".rateLimit.rateSet.{{ $limitName }}] period = "{{ $limit.Period }}" average = {{ $limit.Average }} @@ -102,7 +103,7 @@ {{end}} {{ $headers := getHeaders $service.Attributes }} - {{ if $headers }} + {{if $headers }} [frontends."frontend-{{ $service.ServiceName }}".headers] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} @@ -120,33 +121,33 @@ ReferrerPolicy = "{{ $headers.ReferrerPolicy }}" IsDevelopment = {{ $headers.IsDevelopment }} - {{ if $headers.AllowedHosts }} - AllowedHosts = [{{ range $headers.AllowedHosts }} + {{if $headers.AllowedHosts }} + AllowedHosts = [{{range $headers.AllowedHosts }} "{{.}}", {{end}}] {{end}} - {{ if $headers.HostsProxyHeaders }} - HostsProxyHeaders = [{{ range $headers.HostsProxyHeaders }} + {{if $headers.HostsProxyHeaders }} + HostsProxyHeaders = [{{range $headers.HostsProxyHeaders }} "{{.}}", {{end}}] {{end}} - {{ if $headers.CustomRequestHeaders }} + {{if $headers.CustomRequestHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.customRequestHeaders] - {{ range $k, $v := $headers.CustomRequestHeaders }} + {{range $k, $v := $headers.CustomRequestHeaders }} {{$k}} = "{{$v}}" {{end}} {{end}} - {{ if $headers.CustomResponseHeaders }} + {{if $headers.CustomResponseHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.customResponseHeaders] - {{ range $k, $v := $headers.CustomResponseHeaders }} + {{range $k, $v := $headers.CustomResponseHeaders }} {{$k}} = "{{$v}}" {{end}} {{end}} - {{ if $headers.SSLProxyHeaders }} + {{if $headers.SSLProxyHeaders }} [frontends."frontend-{{ $service.ServiceName }}".headers.SSLProxyHeaders] {{range $k, $v := $headers.SSLProxyHeaders}} {{$k}} = "{{$v}}"