1
0
mirror of https://github.com/containous/traefik.git synced 2024-12-23 17:34:13 +03:00

Fix Consul catalog prefix flags

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2017-04-24 15:09:28 +02:00
parent 37e40bc776
commit af1d0a7dce
No known key found for this signature in database
GPG Key ID: D808B4C167352E59
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