Merge pull request #347 from keis/consul-catalog-replace-space-in-tags

Replace whitespace in tags in consul_catalog
This commit is contained in:
Vincent Demeester 2016-05-07 17:26:17 +02:00
commit b5716abd3e
2 changed files with 15 additions and 2 deletions

View file

@ -133,9 +133,11 @@ func (provider *ConsulCatalog) getBackendAddress(node *api.ServiceEntry) string
func (provider *ConsulCatalog) getBackendName(node *api.ServiceEntry, index int) string { func (provider *ConsulCatalog) getBackendName(node *api.ServiceEntry, index int) string {
serviceName := node.Service.Service + "--" + node.Service.Address + "--" + strconv.Itoa(node.Service.Port) serviceName := node.Service.Service + "--" + node.Service.Address + "--" + strconv.Itoa(node.Service.Port)
if len(node.Service.Tags) > 0 {
serviceName += "--" + strings.Join(node.Service.Tags, "--") for _, tag := range node.Service.Tags {
serviceName += "--" + normalize(tag)
} }
serviceName = strings.Replace(serviceName, ".", "-", -1) serviceName = strings.Replace(serviceName, ".", "-", -1)
serviceName = strings.Replace(serviceName, "=", "-", -1) serviceName = strings.Replace(serviceName, "=", "-", -1)

View file

@ -154,6 +154,17 @@ func TestConsulCatalogGetBackendName(t *testing.T) {
}, },
expected: "api--10-0-0-1--80--traefik-weight-42--traefik-enable-true--1", expected: "api--10-0-0-1--80--traefik-weight-42--traefik-enable-true--1",
}, },
{
node: &api.ServiceEntry{
Service: &api.AgentService{
Service: "api",
Address: "10.0.0.1",
Port: 80,
Tags: []string{"a funny looking tag"},
},
},
expected: "api--10-0-0-1--80--a-funny-looking-tag--2",
},
} }
for i, e := range services { for i, e := range services {