Split consul and consul catalog.

This commit is contained in:
Ludovic Fernandez 2018-01-04 15:56:03 +01:00 committed by Traefiker
parent 06d528a2bd
commit 61ecb4cd18
7 changed files with 89 additions and 86 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/containous/traefik/provider" "github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/boltdb" "github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul" "github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker" "github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb" "github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs" "github.com/containous/traefik/provider/ecs"
@ -333,7 +334,7 @@ func TestDo_globalConfiguration(t *testing.T) {
}, },
RespectReadinessChecks: true, RespectReadinessChecks: true,
} }
config.ConsulCatalog = &consul.CatalogProvider{ config.ConsulCatalog = &consulcatalog.Provider{
BaseProvider: provider.BaseProvider{ BaseProvider: provider.BaseProvider{
Watch: true, Watch: true,
Filename: "ConsulCatalog Filename", Filename: "ConsulCatalog Filename",

View file

@ -11,6 +11,7 @@ import (
"github.com/containous/traefik/ping" "github.com/containous/traefik/ping"
"github.com/containous/traefik/provider/boltdb" "github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul" "github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker" "github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb" "github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs" "github.com/containous/traefik/provider/ecs"
@ -94,7 +95,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
defaultConsul.Constraints = types.Constraints{} defaultConsul.Constraints = types.Constraints{}
// default CatalogProvider // default CatalogProvider
var defaultConsulCatalog consul.CatalogProvider var defaultConsulCatalog consulcatalog.Provider
defaultConsulCatalog.Endpoint = "127.0.0.1:8500" defaultConsulCatalog.Endpoint = "127.0.0.1:8500"
defaultConsulCatalog.ExposedByDefault = true defaultConsulCatalog.ExposedByDefault = true
defaultConsulCatalog.Constraints = types.Constraints{} defaultConsulCatalog.Constraints = types.Constraints{}

View file

@ -13,6 +13,7 @@ import (
"github.com/containous/traefik/ping" "github.com/containous/traefik/ping"
"github.com/containous/traefik/provider/boltdb" "github.com/containous/traefik/provider/boltdb"
"github.com/containous/traefik/provider/consul" "github.com/containous/traefik/provider/consul"
"github.com/containous/traefik/provider/consulcatalog"
"github.com/containous/traefik/provider/docker" "github.com/containous/traefik/provider/docker"
"github.com/containous/traefik/provider/dynamodb" "github.com/containous/traefik/provider/dynamodb"
"github.com/containous/traefik/provider/ecs" "github.com/containous/traefik/provider/ecs"
@ -79,7 +80,7 @@ type GlobalConfiguration struct {
File *file.Provider `description:"Enable File backend with default settings" export:"true"` File *file.Provider `description:"Enable File backend with default settings" export:"true"`
Marathon *marathon.Provider `description:"Enable Marathon backend with default settings" export:"true"` Marathon *marathon.Provider `description:"Enable Marathon backend with default settings" export:"true"`
Consul *consul.Provider `description:"Enable Consul backend with default settings" export:"true"` Consul *consul.Provider `description:"Enable Consul backend with default settings" export:"true"`
ConsulCatalog *consul.CatalogProvider `description:"Enable Consul catalog backend with default settings" export:"true"` ConsulCatalog *consulcatalog.Provider `description:"Enable Consul catalog backend with default settings" export:"true"`
Etcd *etcd.Provider `description:"Enable Etcd backend with default settings" export:"true"` Etcd *etcd.Provider `description:"Enable Etcd backend with default settings" export:"true"`
Zookeeper *zk.Provider `description:"Enable Zookeeper backend with default settings" export:"true"` Zookeeper *zk.Provider `description:"Enable Zookeeper backend with default settings" export:"true"`
Boltdb *boltdb.Provider `description:"Enable Boltdb backend with default settings" export:"true"` Boltdb *boltdb.Provider `description:"Enable Boltdb backend with default settings" export:"true"`

View file

@ -1,4 +1,4 @@
package consul package consulcatalog
import ( import (
"errors" "errors"
@ -22,10 +22,10 @@ const (
DefaultWatchWaitTime = 15 * time.Second DefaultWatchWaitTime = 15 * time.Second
) )
var _ provider.Provider = (*CatalogProvider)(nil) var _ provider.Provider = (*Provider)(nil)
// CatalogProvider holds configurations of the Consul catalog provider. // Provider holds configurations of the Consul catalog provider.
type CatalogProvider struct { type Provider struct {
provider.BaseProvider `mapstructure:",squash" export:"true"` provider.BaseProvider `mapstructure:",squash" export:"true"`
Endpoint string `description:"Consul server endpoint"` Endpoint string `description:"Consul server endpoint"`
Domain string `description:"Default domain used"` Domain string `description:"Default domain used"`
@ -85,7 +85,7 @@ func (a nodeSorter) Less(i int, j int) bool {
// Provide allows the consul catalog provider to provide configurations to traefik // Provide allows the consul catalog provider to provide configurations to traefik
// using the given configuration channel. // using the given configuration channel.
func (p *CatalogProvider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error { func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
config := api.DefaultConfig() config := api.DefaultConfig()
config.Address = p.Endpoint config.Address = p.Endpoint
client, err := api.NewClient(config) client, err := api.NewClient(config)
@ -112,7 +112,7 @@ func (p *CatalogProvider) Provide(configurationChan chan<- types.ConfigMessage,
return err return err
} }
func (p *CatalogProvider) watch(configurationChan chan<- types.ConfigMessage, stop chan bool) error { func (p *Provider) watch(configurationChan chan<- types.ConfigMessage, stop chan bool) error {
stopCh := make(chan struct{}) stopCh := make(chan struct{})
watchCh := make(chan map[string][]string) watchCh := make(chan map[string][]string)
errorCh := make(chan error) errorCh := make(chan error)
@ -147,7 +147,7 @@ func (p *CatalogProvider) watch(configurationChan chan<- types.ConfigMessage, st
} }
} }
func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) { func (p *Provider) watchCatalogServices(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
catalog := p.client.Catalog() catalog := p.client.Catalog()
safe.Go(func() { safe.Go(func() {
@ -216,7 +216,7 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c
}) })
} }
func (p *CatalogProvider) watchHealthState(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) { func (p *Provider) watchHealthState(stopCh <-chan struct{}, watchCh chan<- map[string][]string, errorCh chan<- error) {
health := p.client.Health() health := p.client.Health()
catalog := p.client.Catalog() catalog := p.client.Catalog()
@ -287,7 +287,7 @@ func (p *CatalogProvider) watchHealthState(stopCh <-chan struct{}, watchCh chan<
}) })
} }
func (p *CatalogProvider) getNodes(index map[string][]string) ([]catalogUpdate, error) { func (p *Provider) getNodes(index map[string][]string) ([]catalogUpdate, error) {
visited := make(map[string]bool) visited := make(map[string]bool)
var nodes []catalogUpdate var nodes []catalogUpdate
@ -383,7 +383,7 @@ func getServicePorts(services []*api.CatalogService) []int {
return servicePorts return servicePorts
} }
func (p *CatalogProvider) healthyNodes(service string) (catalogUpdate, error) { func (p *Provider) healthyNodes(service string) (catalogUpdate, error) {
health := p.client.Health() health := p.client.Health()
data, _, err := health.Service(service, "", true, &api.QueryOptions{}) data, _, err := health.Service(service, "", true, &api.QueryOptions{})
if err != nil { if err != nil {
@ -412,7 +412,7 @@ func (p *CatalogProvider) healthyNodes(service string) (catalogUpdate, error) {
}, nil }, nil
} }
func (p *CatalogProvider) nodeFilter(service string, node *api.ServiceEntry) bool { func (p *Provider) nodeFilter(service string, node *api.ServiceEntry) bool {
// Filter disabled application. // Filter disabled application.
if !p.isServiceEnabled(node) { if !p.isServiceEnabled(node) {
log.Debugf("Filtering disabled Consul service %s", service) log.Debugf("Filtering disabled Consul service %s", service)
@ -429,11 +429,11 @@ func (p *CatalogProvider) nodeFilter(service string, node *api.ServiceEntry) boo
return true return true
} }
func (p *CatalogProvider) isServiceEnabled(node *api.ServiceEntry) bool { func (p *Provider) isServiceEnabled(node *api.ServiceEntry) bool {
return p.getBoolAttribute(label.SuffixEnable, node.Service.Tags, p.ExposedByDefault) return p.getBoolAttribute(label.SuffixEnable, node.Service.Tags, p.ExposedByDefault)
} }
func (p *CatalogProvider) getConstraintTags(tags []string) []string { func (p *Provider) getConstraintTags(tags []string) []string {
var values []string var values []string
prefix := p.getPrefixedName("tags=") prefix := p.getPrefixedName("tags=")

View file

@ -1,4 +1,4 @@
package consul package consulcatalog
import ( import (
"bytes" "bytes"
@ -17,7 +17,7 @@ import (
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
) )
func (p *CatalogProvider) buildConfiguration(catalog []catalogUpdate) *types.Configuration { func (p *Provider) buildConfiguration(catalog []catalogUpdate) *types.Configuration {
var FuncMap = template.FuncMap{ var FuncMap = template.FuncMap{
"getAttribute": p.getAttribute, "getAttribute": p.getAttribute,
"getTag": getTag, "getTag": getTag,
@ -85,7 +85,7 @@ func (p *CatalogProvider) buildConfiguration(catalog []catalogUpdate) *types.Con
return configuration return configuration
} }
func (p *CatalogProvider) setupFrontEndRuleTemplate() { func (p *Provider) setupFrontEndRuleTemplate() {
var FuncMap = template.FuncMap{ var FuncMap = template.FuncMap{
"getAttribute": p.getAttribute, "getAttribute": p.getAttribute,
"getTag": getTag, "getTag": getTag,
@ -97,7 +97,7 @@ func (p *CatalogProvider) setupFrontEndRuleTemplate() {
// Specific functions // Specific functions
func (p *CatalogProvider) getFrontendRule(service serviceUpdate) string { func (p *Provider) getFrontendRule(service serviceUpdate) string {
customFrontendRule := p.getAttribute(label.SuffixFrontendRule, service.Attributes, "") customFrontendRule := p.getAttribute(label.SuffixFrontendRule, service.Attributes, "")
if customFrontendRule == "" { if customFrontendRule == "" {
customFrontendRule = p.FrontEndRule customFrontendRule = p.FrontEndRule
@ -131,7 +131,7 @@ func (p *CatalogProvider) getFrontendRule(service serviceUpdate) string {
} }
// Deprecated // Deprecated
func (p *CatalogProvider) hasMaxConnAttributes(attributes []string) bool { func (p *Provider) hasMaxConnAttributes(attributes []string) bool {
amount := p.getAttribute(label.SuffixBackendMaxConnAmount, attributes, "") amount := p.getAttribute(label.SuffixBackendMaxConnAmount, attributes, "")
extractorFunc := p.getAttribute(label.SuffixBackendMaxConnExtractorFunc, attributes, "") extractorFunc := p.getAttribute(label.SuffixBackendMaxConnExtractorFunc, attributes, "")
return amount != "" && extractorFunc != "" return amount != "" && extractorFunc != ""
@ -178,7 +178,7 @@ func getServerName(node *api.ServiceEntry, index int) string {
// TODO: Deprecated // TODO: Deprecated
// replaced by Stickiness // replaced by Stickiness
// Deprecated // Deprecated
func (p *CatalogProvider) getSticky(tags []string) string { func (p *Provider) getSticky(tags []string) string {
stickyTag := p.getAttribute(label.SuffixBackendLoadBalancerSticky, tags, "") stickyTag := p.getAttribute(label.SuffixBackendLoadBalancerSticky, tags, "")
if len(stickyTag) > 0 { if len(stickyTag) > 0 {
log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness) log.Warnf("Deprecated configuration found: %s. Please use %s.", label.TraefikBackendLoadBalancerSticky, label.TraefikBackendLoadBalancerStickiness)
@ -189,18 +189,18 @@ func (p *CatalogProvider) getSticky(tags []string) string {
} }
// Deprecated // Deprecated
func (p *CatalogProvider) hasStickinessLabel(tags []string) bool { func (p *Provider) hasStickinessLabel(tags []string) bool {
stickinessTag := p.getAttribute(label.SuffixBackendLoadBalancerStickiness, tags, "") stickinessTag := p.getAttribute(label.SuffixBackendLoadBalancerStickiness, tags, "")
return len(stickinessTag) > 0 && strings.EqualFold(strings.TrimSpace(stickinessTag), "true") return len(stickinessTag) > 0 && strings.EqualFold(strings.TrimSpace(stickinessTag), "true")
} }
// Deprecated // Deprecated
func (p *CatalogProvider) getStickinessCookieName(tags []string) string { func (p *Provider) getStickinessCookieName(tags []string) string {
return p.getAttribute(label.SuffixBackendLoadBalancerStickinessCookieName, tags, "") return p.getAttribute(label.SuffixBackendLoadBalancerStickinessCookieName, tags, "")
} }
// Deprecated // Deprecated
func (p *CatalogProvider) getWeight(tags []string) int { func (p *Provider) getWeight(tags []string) int {
weight := p.getIntAttribute(label.SuffixWeight, tags, 0) weight := p.getIntAttribute(label.SuffixWeight, tags, 0)
// Deprecated // Deprecated
@ -215,7 +215,7 @@ func (p *CatalogProvider) getWeight(tags []string) int {
return weight return weight
} }
func (p *CatalogProvider) getCircuitBreaker(tags []string) *types.CircuitBreaker { func (p *Provider) getCircuitBreaker(tags []string) *types.CircuitBreaker {
circuitBreaker := p.getAttribute(label.SuffixBackendCircuitBreakerExpression, tags, "") circuitBreaker := p.getAttribute(label.SuffixBackendCircuitBreakerExpression, tags, "")
if p.hasAttribute(label.SuffixBackendCircuitBreaker, tags) { if p.hasAttribute(label.SuffixBackendCircuitBreaker, tags) {
@ -232,7 +232,7 @@ func (p *CatalogProvider) getCircuitBreaker(tags []string) *types.CircuitBreaker
return &types.CircuitBreaker{Expression: circuitBreaker} return &types.CircuitBreaker{Expression: circuitBreaker}
} }
func (p *CatalogProvider) getLoadBalancer(tags []string) *types.LoadBalancer { func (p *Provider) getLoadBalancer(tags []string) *types.LoadBalancer {
rawSticky := p.getSticky(tags) rawSticky := p.getSticky(tags)
sticky, err := strconv.ParseBool(rawSticky) sticky, err := strconv.ParseBool(rawSticky)
if err != nil { if err != nil {
@ -265,7 +265,7 @@ func (p *CatalogProvider) getLoadBalancer(tags []string) *types.LoadBalancer {
return lb return lb
} }
func (p *CatalogProvider) getMaxConn(tags []string) *types.MaxConn { func (p *Provider) getMaxConn(tags []string) *types.MaxConn {
amount := p.getInt64Attribute(label.SuffixBackendMaxConnAmount, tags, math.MinInt64) amount := p.getInt64Attribute(label.SuffixBackendMaxConnAmount, tags, math.MinInt64)
extractorFunc := p.getAttribute(label.SuffixBackendMaxConnExtractorFunc, tags, label.DefaultBackendMaxconnExtractorFunc) extractorFunc := p.getAttribute(label.SuffixBackendMaxConnExtractorFunc, tags, label.DefaultBackendMaxconnExtractorFunc)
@ -279,7 +279,7 @@ func (p *CatalogProvider) getMaxConn(tags []string) *types.MaxConn {
} }
} }
func (p *CatalogProvider) getHealthCheck(tags []string) *types.HealthCheck { func (p *Provider) getHealthCheck(tags []string) *types.HealthCheck {
path := p.getAttribute(label.SuffixBackendHealthCheckPath, tags, "") path := p.getAttribute(label.SuffixBackendHealthCheckPath, tags, "")
if len(path) == 0 { if len(path) == 0 {
@ -296,7 +296,7 @@ func (p *CatalogProvider) getHealthCheck(tags []string) *types.HealthCheck {
} }
} }
func (p *CatalogProvider) getRedirect(tags []string) *types.Redirect { func (p *Provider) getRedirect(tags []string) *types.Redirect {
if p.hasAttribute(label.SuffixFrontendRedirectEntryPoint, tags) { if p.hasAttribute(label.SuffixFrontendRedirectEntryPoint, tags) {
return &types.Redirect{ return &types.Redirect{
EntryPoint: p.getAttribute(label.SuffixFrontendRedirectEntryPoint, tags, ""), EntryPoint: p.getAttribute(label.SuffixFrontendRedirectEntryPoint, tags, ""),
@ -313,14 +313,14 @@ func (p *CatalogProvider) getRedirect(tags []string) *types.Redirect {
return nil return nil
} }
func (p *CatalogProvider) getErrorPages(tags []string) map[string]*types.ErrorPage { func (p *Provider) getErrorPages(tags []string) map[string]*types.ErrorPage {
labels := p.parseTagsToNeutralLabels(tags) labels := p.parseTagsToNeutralLabels(tags)
prefix := label.Prefix + label.BaseFrontendErrorPage prefix := label.Prefix + label.BaseFrontendErrorPage
return label.ParseErrorPages(labels, prefix, label.RegexpFrontendErrorPage) return label.ParseErrorPages(labels, prefix, label.RegexpFrontendErrorPage)
} }
func (p *CatalogProvider) getRateLimit(tags []string) *types.RateLimit { func (p *Provider) getRateLimit(tags []string) *types.RateLimit {
extractorFunc := p.getAttribute(label.SuffixFrontendRateLimitExtractorFunc, tags, "") extractorFunc := p.getAttribute(label.SuffixFrontendRateLimitExtractorFunc, tags, "")
if len(extractorFunc) == 0 { if len(extractorFunc) == 0 {
return nil return nil
@ -337,7 +337,7 @@ func (p *CatalogProvider) getRateLimit(tags []string) *types.RateLimit {
} }
} }
func (p *CatalogProvider) getHeaders(tags []string) *types.Headers { func (p *Provider) getHeaders(tags []string) *types.Headers {
headers := &types.Headers{ headers := &types.Headers{
CustomRequestHeaders: p.getMapAttribute(label.SuffixFrontendRequestHeaders, tags), CustomRequestHeaders: p.getMapAttribute(label.SuffixFrontendRequestHeaders, tags),
CustomResponseHeaders: p.getMapAttribute(label.SuffixFrontendResponseHeaders, tags), CustomResponseHeaders: p.getMapAttribute(label.SuffixFrontendResponseHeaders, tags),
@ -370,7 +370,7 @@ func (p *CatalogProvider) getHeaders(tags []string) *types.Headers {
// Base functions // Base functions
func (p *CatalogProvider) parseTagsToNeutralLabels(tags []string) map[string]string { func (p *Provider) parseTagsToNeutralLabels(tags []string) map[string]string {
var labels map[string]string var labels map[string]string
for _, tag := range tags { for _, tag := range tags {
@ -392,19 +392,19 @@ func (p *CatalogProvider) parseTagsToNeutralLabels(tags []string) map[string]str
return labels return labels
} }
func (p *CatalogProvider) getFuncStringAttribute(name string, defaultValue string) func(tags []string) string { func (p *Provider) getFuncStringAttribute(name string, defaultValue string) func(tags []string) string {
return func(tags []string) string { return func(tags []string) string {
return p.getAttribute(name, tags, defaultValue) return p.getAttribute(name, tags, defaultValue)
} }
} }
func (p *CatalogProvider) getFuncSliceAttribute(name string) func(tags []string) []string { func (p *Provider) getFuncSliceAttribute(name string) func(tags []string) []string {
return func(tags []string) []string { return func(tags []string) []string {
return p.getSliceAttribute(name, tags) return p.getSliceAttribute(name, tags)
} }
} }
func (p *CatalogProvider) getMapAttribute(name string, tags []string) map[string]string { func (p *Provider) getMapAttribute(name string, tags []string) map[string]string {
rawValue := getTag(p.getPrefixedName(name), tags, "") rawValue := getTag(p.getPrefixedName(name), tags, "")
if len(rawValue) == 0 { if len(rawValue) == 0 {
@ -414,25 +414,25 @@ func (p *CatalogProvider) getMapAttribute(name string, tags []string) map[string
return label.ParseMapValue(p.getPrefixedName(name), rawValue) return label.ParseMapValue(p.getPrefixedName(name), rawValue)
} }
func (p *CatalogProvider) getFuncIntAttribute(name string, defaultValue int) func(tags []string) int { func (p *Provider) getFuncIntAttribute(name string, defaultValue int) func(tags []string) int {
return func(tags []string) int { return func(tags []string) int {
return p.getIntAttribute(name, tags, defaultValue) return p.getIntAttribute(name, tags, defaultValue)
} }
} }
func (p *CatalogProvider) getFuncBoolAttribute(name string, defaultValue bool) func(tags []string) bool { func (p *Provider) getFuncBoolAttribute(name string, defaultValue bool) func(tags []string) bool {
return func(tags []string) bool { return func(tags []string) bool {
return p.getBoolAttribute(name, tags, defaultValue) return p.getBoolAttribute(name, tags, defaultValue)
} }
} }
func (p *CatalogProvider) getFuncHasAttributePrefix(name string) func(tags []string) bool { func (p *Provider) getFuncHasAttributePrefix(name string) func(tags []string) bool {
return func(tags []string) bool { return func(tags []string) bool {
return p.hasAttributePrefix(name, tags) return p.hasAttributePrefix(name, tags)
} }
} }
func (p *CatalogProvider) getInt64Attribute(name string, tags []string, defaultValue int64) int64 { func (p *Provider) getInt64Attribute(name string, tags []string, defaultValue int64) int64 {
rawValue := getTag(p.getPrefixedName(name), tags, "") rawValue := getTag(p.getPrefixedName(name), tags, "")
if len(rawValue) == 0 { if len(rawValue) == 0 {
@ -447,7 +447,7 @@ func (p *CatalogProvider) getInt64Attribute(name string, tags []string, defaultV
return value return value
} }
func (p *CatalogProvider) getIntAttribute(name string, tags []string, defaultValue int) int { func (p *Provider) getIntAttribute(name string, tags []string, defaultValue int) int {
rawValue := getTag(p.getPrefixedName(name), tags, "") rawValue := getTag(p.getPrefixedName(name), tags, "")
if len(rawValue) == 0 { if len(rawValue) == 0 {
@ -462,7 +462,7 @@ func (p *CatalogProvider) getIntAttribute(name string, tags []string, defaultVal
return value return value
} }
func (p *CatalogProvider) getSliceAttribute(name string, tags []string) []string { func (p *Provider) getSliceAttribute(name string, tags []string) []string {
rawValue := getTag(p.getPrefixedName(name), tags, "") rawValue := getTag(p.getPrefixedName(name), tags, "")
if len(rawValue) == 0 { if len(rawValue) == 0 {
@ -471,7 +471,7 @@ func (p *CatalogProvider) getSliceAttribute(name string, tags []string) []string
return label.SplitAndTrimString(rawValue, ",") return label.SplitAndTrimString(rawValue, ",")
} }
func (p *CatalogProvider) getBoolAttribute(name string, tags []string, defaultValue bool) bool { func (p *Provider) getBoolAttribute(name string, tags []string, defaultValue bool) bool {
rawValue := getTag(p.getPrefixedName(name), tags, "") rawValue := getTag(p.getPrefixedName(name), tags, "")
if len(rawValue) == 0 { if len(rawValue) == 0 {
@ -486,19 +486,19 @@ func (p *CatalogProvider) getBoolAttribute(name string, tags []string, defaultVa
return value return value
} }
func (p *CatalogProvider) hasAttribute(name string, tags []string) bool { func (p *Provider) hasAttribute(name string, tags []string) bool {
return hasTag(p.getPrefixedName(name), tags) return hasTag(p.getPrefixedName(name), tags)
} }
func (p *CatalogProvider) hasAttributePrefix(name string, tags []string) bool { func (p *Provider) hasAttributePrefix(name string, tags []string) bool {
return hasTagPrefix(p.getPrefixedName(name), tags) return hasTagPrefix(p.getPrefixedName(name), tags)
} }
func (p *CatalogProvider) getAttribute(name string, tags []string, defaultValue string) string { func (p *Provider) getAttribute(name string, tags []string, defaultValue string) string {
return getTag(p.getPrefixedName(name), tags, defaultValue) return getTag(p.getPrefixedName(name), tags, defaultValue)
} }
func (p *CatalogProvider) getPrefixedName(name string) string { func (p *Provider) getPrefixedName(name string) string {
if len(p.Prefix) > 0 && len(name) > 0 { if len(p.Prefix) > 0 && len(name) > 0 {
return p.Prefix + "." + name return p.Prefix + "." + name
} }

View file

@ -1,4 +1,4 @@
package consul package consulcatalog
import ( import (
"testing" "testing"
@ -12,8 +12,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestCatalogProviderBuildConfiguration(t *testing.T) { func TestProviderBuildConfiguration(t *testing.T) {
provider := &CatalogProvider{ provider := &Provider{
Domain: "localhost", Domain: "localhost",
Prefix: "traefik", Prefix: "traefik",
ExposedByDefault: false, ExposedByDefault: false,
@ -211,7 +211,7 @@ func TestHasTag(t *testing.T) {
} }
} }
func TestCatalogProviderGetPrefixedName(t *testing.T) { func TestProviderGetPrefixedName(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
name string name string
@ -249,7 +249,7 @@ func TestCatalogProviderGetPrefixedName(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
pro := &CatalogProvider{Prefix: test.prefix} pro := &Provider{Prefix: test.prefix}
actual := pro.getPrefixedName(test.name) actual := pro.getPrefixedName(test.name)
assert.Equal(t, test.expected, actual) assert.Equal(t, test.expected, actual)
@ -258,7 +258,7 @@ func TestCatalogProviderGetPrefixedName(t *testing.T) {
} }
func TestCatalogProviderGetAttribute(t *testing.T) { func TestProviderGetAttribute(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
tags []string tags []string
@ -326,7 +326,7 @@ func TestCatalogProviderGetAttribute(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
p := &CatalogProvider{ p := &Provider{
Domain: "localhost", Domain: "localhost",
Prefix: test.prefix, Prefix: test.prefix,
} }
@ -337,8 +337,8 @@ func TestCatalogProviderGetAttribute(t *testing.T) {
} }
} }
func TestCatalogProviderGetIntAttribute(t *testing.T) { func TestProviderGetIntAttribute(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -388,8 +388,8 @@ func TestCatalogProviderGetIntAttribute(t *testing.T) {
} }
} }
func TestCatalogProviderGetInt64Attribute(t *testing.T) { func TestProviderGetInt64Attribute(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -439,8 +439,8 @@ func TestCatalogProviderGetInt64Attribute(t *testing.T) {
} }
} }
func TestCatalogProviderGetBoolAttribute(t *testing.T) { func TestProviderGetBoolAttribute(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -490,8 +490,8 @@ func TestCatalogProviderGetBoolAttribute(t *testing.T) {
} }
} }
func TestCatalogProviderGetSliceAttribute(t *testing.T) { func TestProviderGetSliceAttribute(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -545,7 +545,7 @@ func TestCatalogProviderGetSliceAttribute(t *testing.T) {
} }
} }
func TestCatalogProviderGetFrontendRule(t *testing.T) { func TestProviderGetFrontendRule(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
service serviceUpdate service serviceUpdate
@ -597,7 +597,7 @@ func TestCatalogProviderGetFrontendRule(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
p := &CatalogProvider{ p := &Provider{
Domain: "localhost", Domain: "localhost",
Prefix: "traefik", Prefix: "traefik",
FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}", FrontEndRule: "Host:{{.ServiceName}}.{{.Domain}}",
@ -654,7 +654,7 @@ func TestGetBackendAddress(t *testing.T) {
} }
} }
func TestCatalogProviderGetServerName(t *testing.T) { func TestProviderGetServerName(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
node *api.ServiceEntry node *api.ServiceEntry
@ -711,7 +711,7 @@ func TestCatalogProviderGetServerName(t *testing.T) {
} }
func TestHasStickinessLabel(t *testing.T) { func TestHasStickinessLabel(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -752,8 +752,8 @@ func TestHasStickinessLabel(t *testing.T) {
} }
} }
func TestCatalogProviderGetCircuitBreaker(t *testing.T) { func TestProviderGetCircuitBreaker(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -788,8 +788,8 @@ func TestCatalogProviderGetCircuitBreaker(t *testing.T) {
} }
} }
func TestCatalogProviderGetLoadBalancer(t *testing.T) { func TestProviderGetLoadBalancer(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -887,8 +887,8 @@ func TestCatalogProviderGetLoadBalancer(t *testing.T) {
} }
} }
func TestCatalogProviderGetMaxConn(t *testing.T) { func TestProviderGetMaxConn(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -952,8 +952,8 @@ func TestCatalogProviderGetMaxConn(t *testing.T) {
} }
} }
func TestCatalogProviderGetHealthCheck(t *testing.T) { func TestProviderGetHealthCheck(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -1002,8 +1002,8 @@ func TestCatalogProviderGetHealthCheck(t *testing.T) {
} }
} }
func TestCatalogProviderGetRedirect(t *testing.T) { func TestProviderGetRedirect(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -1062,8 +1062,8 @@ func TestCatalogProviderGetRedirect(t *testing.T) {
} }
} }
func TestCatalogProviderGetErrorPages(t *testing.T) { func TestProviderGetErrorPages(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -1114,8 +1114,8 @@ func TestCatalogProviderGetErrorPages(t *testing.T) {
} }
} }
func TestCatalogProviderGetRateLimit(t *testing.T) { func TestProviderGetRateLimit(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }
@ -1170,8 +1170,8 @@ func TestCatalogProviderGetRateLimit(t *testing.T) {
} }
} }
func TestCatalogProviderGetHeaders(t *testing.T) { func TestProviderGetHeaders(t *testing.T) {
p := &CatalogProvider{ p := &Provider{
Prefix: "traefik", Prefix: "traefik",
} }

View file

@ -1,4 +1,4 @@
package consul package consulcatalog
import ( import (
"sort" "sort"
@ -446,7 +446,7 @@ func TestFilterEnabled(t *testing.T) {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
provider := &CatalogProvider{ provider := &Provider{
Domain: "localhost", Domain: "localhost",
Prefix: "traefik", Prefix: "traefik",
ExposedByDefault: test.exposedByDefault, ExposedByDefault: test.exposedByDefault,
@ -787,7 +787,7 @@ func TestHasChanged(t *testing.T) {
} }
func TestGetConstraintTags(t *testing.T) { func TestGetConstraintTags(t *testing.T) {
provider := &CatalogProvider{ provider := &Provider{
Domain: "localhost", Domain: "localhost",
Prefix: "traefik", Prefix: "traefik",
} }