1
0
Fork 0

refactor: Consul Catalog labels.

This commit is contained in:
Fernandez Ludovic 2018-03-28 02:18:07 +02:00 committed by Traefiker Bot
parent 46db91ce73
commit ff61cc971e
14 changed files with 1715 additions and 2018 deletions

View file

@ -2,6 +2,7 @@ package consulcatalog
import (
"errors"
"strconv"
"strings"
"sync"
"text/template"
@ -48,8 +49,9 @@ type Service struct {
}
type serviceUpdate struct {
ServiceName string
Attributes []string
ServiceName string
Attributes []string
TraefikLabels map[string]string
}
type catalogUpdate struct {
@ -446,10 +448,13 @@ func (p *Provider) healthyNodes(service string) (catalogUpdate, error) {
).(map[string]bool)).([]string)
}, []string{}, nodes).([]string)
labels := tagsToNeutralLabels(tags, p.Prefix)
return catalogUpdate{
Service: &serviceUpdate{
ServiceName: service,
Attributes: tags,
ServiceName: service,
Attributes: tags,
TraefikLabels: labels,
},
Nodes: nodes,
}, nil
@ -473,7 +478,18 @@ func (p *Provider) nodeFilter(service string, node *api.ServiceEntry) bool {
}
func (p *Provider) isServiceEnabled(node *api.ServiceEntry) bool {
return p.getBoolAttribute(label.SuffixEnable, node.Service.Tags, p.ExposedByDefault)
rawValue := getTag(p.getPrefixedName(label.SuffixEnable), node.Service.Tags, "")
if len(rawValue) == 0 {
return p.ExposedByDefault
}
value, err := strconv.ParseBool(rawValue)
if err != nil {
log.Errorf("Invalid value for %s: %s", label.SuffixEnable, rawValue)
return p.ExposedByDefault
}
return value
}
func (p *Provider) getConstraintTags(tags []string) []string {