diff --git a/provider/consul/consul_catalog.go b/provider/consul/consul_catalog.go index a6eea2bd6..794f04996 100644 --- a/provider/consul/consul_catalog.go +++ b/provider/consul/consul_catalog.go @@ -22,8 +22,6 @@ import ( const ( // DefaultWatchWaitTime is the duration to wait when polling consul DefaultWatchWaitTime = 15 * time.Second - // DefaultConsulCatalogTagPrefix is a prefix for additional service/node configurations - DefaultConsulCatalogTagPrefix = "traefik" ) var _ provider.Provider = (*CatalogProvider)(nil) @@ -33,8 +31,8 @@ type CatalogProvider struct { provider.BaseProvider `mapstructure:",squash"` Endpoint string `description:"Consul server endpoint"` Domain string `description:"Default domain used"` + Prefix string `description:"Prefix used for Consul catalog tags"` client *api.Client - Prefix string } type serviceUpdate struct { @@ -190,8 +188,8 @@ func (p *CatalogProvider) getBackendName(node *api.ServiceEntry, index int) stri func (p *CatalogProvider) getAttribute(name string, tags []string, defaultValue string) string { for _, tag := range tags { - if strings.Index(strings.ToLower(tag), DefaultConsulCatalogTagPrefix+".") == 0 { - if kv := strings.SplitN(tag[len(DefaultConsulCatalogTagPrefix+"."):], "=", 2); len(kv) == 2 && strings.ToLower(kv[0]) == strings.ToLower(name) { + if strings.Index(strings.ToLower(tag), p.Prefix+".") == 0 { + if kv := strings.SplitN(tag[len(p.Prefix+"."):], "=", 2); len(kv) == 2 && strings.ToLower(kv[0]) == strings.ToLower(name) { return kv[1] } } @@ -203,8 +201,8 @@ func (p *CatalogProvider) getContraintTags(tags []string) []string { var list []string for _, tag := range tags { - if strings.Index(strings.ToLower(tag), DefaultConsulCatalogTagPrefix+".tags=") == 0 { - splitedTags := strings.Split(tag[len(DefaultConsulCatalogTagPrefix+".tags="):], ",") + if strings.Index(strings.ToLower(tag), p.Prefix+".tags=") == 0 { + splitedTags := strings.Split(tag[len(p.Prefix+".tags="):], ",") list = append(list, splitedTags...) } } diff --git a/provider/consul/consul_catalog_test.go b/provider/consul/consul_catalog_test.go index 656933b65..a76cef2da 100644 --- a/provider/consul/consul_catalog_test.go +++ b/provider/consul/consul_catalog_test.go @@ -12,6 +12,7 @@ import ( func TestConsulCatalogGetFrontendRule(t *testing.T) { provider := &CatalogProvider{ Domain: "localhost", + Prefix: "traefik", } services := []struct { @@ -47,6 +48,7 @@ func TestConsulCatalogGetFrontendRule(t *testing.T) { func TestConsulCatalogGetAttribute(t *testing.T) { provider := &CatalogProvider{ Domain: "localhost", + Prefix: "traefik", } services := []struct { @@ -86,6 +88,7 @@ func TestConsulCatalogGetAttribute(t *testing.T) { func TestConsulCatalogGetBackendAddress(t *testing.T) { provider := &CatalogProvider{ Domain: "localhost", + Prefix: "traefik", } services := []struct { @@ -127,6 +130,7 @@ func TestConsulCatalogGetBackendAddress(t *testing.T) { func TestConsulCatalogGetBackendName(t *testing.T) { provider := &CatalogProvider{ Domain: "localhost", + Prefix: "traefik", } services := []struct { @@ -179,6 +183,7 @@ func TestConsulCatalogGetBackendName(t *testing.T) { func TestConsulCatalogBuildConfig(t *testing.T) { provider := &CatalogProvider{ Domain: "localhost", + Prefix: "traefik", } cases := []struct { diff --git a/server/configuration.go b/server/configuration.go index 85a2b82d2..b3d7df0e9 100644 --- a/server/configuration.go +++ b/server/configuration.go @@ -385,6 +385,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration { var defaultConsulCatalog consul.CatalogProvider defaultConsulCatalog.Endpoint = "127.0.0.1:8500" defaultConsulCatalog.Constraints = types.Constraints{} + defaultConsulCatalog.Prefix = "traefik" // default Etcd var defaultEtcd etcd.Provider