Merge pull request #1486 from containous/fix-consul-catalog-flags

Fix Consul catalog prefix flags
This commit is contained in:
Ludovic Fernandez 2017-04-25 11:13:28 +02:00 committed by GitHub
commit 4f2a2d573d
3 changed files with 11 additions and 7 deletions

View file

@ -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...)
}
}

View file

@ -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 {

View file

@ -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