Skip to content

Commit

Permalink
Merge pull request traefik#1486 from containous/fix-consul-catalog-flags
Browse files Browse the repository at this point in the history
Fix Consul catalog prefix flags
  • Loading branch information
ldez authored Apr 25, 2017
2 parents 37e40bc + af1d0a7 commit 4f2a2d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 5 additions & 7 deletions provider/consul/consul_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
}
}
Expand All @@ -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...)
}
}
Expand Down
5 changes: 5 additions & 0 deletions provider/consul/consul_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func TestConsulCatalogGetFrontendRule(t *testing.T) {
provider := &CatalogProvider{
Domain: "localhost",
Prefix: "traefik",
}

services := []struct {
Expand Down Expand Up @@ -47,6 +48,7 @@ func TestConsulCatalogGetFrontendRule(t *testing.T) {
func TestConsulCatalogGetAttribute(t *testing.T) {
provider := &CatalogProvider{
Domain: "localhost",
Prefix: "traefik",
}

services := []struct {
Expand Down Expand Up @@ -86,6 +88,7 @@ func TestConsulCatalogGetAttribute(t *testing.T) {
func TestConsulCatalogGetBackendAddress(t *testing.T) {
provider := &CatalogProvider{
Domain: "localhost",
Prefix: "traefik",
}

services := []struct {
Expand Down Expand Up @@ -127,6 +130,7 @@ func TestConsulCatalogGetBackendAddress(t *testing.T) {
func TestConsulCatalogGetBackendName(t *testing.T) {
provider := &CatalogProvider{
Domain: "localhost",
Prefix: "traefik",
}

services := []struct {
Expand Down Expand Up @@ -179,6 +183,7 @@ func TestConsulCatalogGetBackendName(t *testing.T) {
func TestConsulCatalogBuildConfig(t *testing.T) {
provider := &CatalogProvider{
Domain: "localhost",
Prefix: "traefik",
}

cases := []struct {
Expand Down
1 change: 1 addition & 0 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f2a2d5

Please sign in to comment.