feat(rancher): added constraint management for rancher provider
This commit is contained in:
parent
b5283391dd
commit
8de107866f
4 changed files with 34 additions and 0 deletions
|
@ -117,6 +117,7 @@ Supported backends:
|
|||
- Zookeeper
|
||||
- Etcd
|
||||
- Consul Catalog
|
||||
- Rancher
|
||||
|
||||
Supported filters:
|
||||
|
||||
|
|
|
@ -234,6 +234,7 @@ func getenv(key, fallback string) string {
|
|||
// Provide allows the rancher provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
|
||||
p.Constraints = append(p.Constraints, constraints...)
|
||||
|
||||
safe.Go(func() {
|
||||
operation := func() error {
|
||||
|
@ -485,6 +486,14 @@ func (p *Provider) serviceFilter(service rancherData) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
constraintTags := strings.Split(service.Labels["traefik.tags"], ",")
|
||||
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
|
||||
if failingConstraint != nil {
|
||||
log.Debugf("Filtering service %s with constraint %s", service.Name, failingConstraint.String())
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Only filter services by Health (HealthState) and State if EnableServiceHealthFilter is true
|
||||
if p.EnableServiceHealthFilter {
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ func TestRancherServiceFilter(t *testing.T) {
|
|||
EnableServiceHealthFilter: true,
|
||||
}
|
||||
|
||||
constraint, _ := types.NewConstraint("tag==ch*se")
|
||||
provider.Constraints = types.Constraints{constraint}
|
||||
|
||||
services := []struct {
|
||||
service rancherData
|
||||
expected bool
|
||||
|
@ -54,6 +57,7 @@ func TestRancherServiceFilter(t *testing.T) {
|
|||
{
|
||||
service: rancherData{
|
||||
Labels: map[string]string{
|
||||
"traefik.tags": "not-cheesy",
|
||||
"traefik.port": "80",
|
||||
"traefik.enable": "true",
|
||||
},
|
||||
|
@ -65,6 +69,7 @@ func TestRancherServiceFilter(t *testing.T) {
|
|||
{
|
||||
service: rancherData{
|
||||
Labels: map[string]string{
|
||||
"traefik.tags": "cheese",
|
||||
"traefik.port": "80",
|
||||
"traefik.enable": "true",
|
||||
},
|
||||
|
@ -76,6 +81,7 @@ func TestRancherServiceFilter(t *testing.T) {
|
|||
{
|
||||
service: rancherData{
|
||||
Labels: map[string]string{
|
||||
"traefik.tags": "cheeeeese",
|
||||
"traefik.port": "80",
|
||||
"traefik.enable": "true",
|
||||
},
|
||||
|
@ -84,6 +90,18 @@ func TestRancherServiceFilter(t *testing.T) {
|
|||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
service: rancherData{
|
||||
Labels: map[string]string{
|
||||
"traefik.tags": "chose",
|
||||
"traefik.port": "80",
|
||||
"traefik.enable": "true",
|
||||
},
|
||||
Health: "healthy",
|
||||
State: "active",
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, e := range services {
|
||||
|
|
|
@ -1081,6 +1081,12 @@
|
|||
# Required
|
||||
# SecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# Constraints
|
||||
#
|
||||
# Optional
|
||||
#
|
||||
# constraints = ["tag==api", "tag==chee*e"]
|
||||
# Matching with containers having this tag: "traefik.tags=cheese,wine"
|
||||
|
||||
################################################################
|
||||
# DynamoDB configuration backend
|
||||
|
|
Loading…
Reference in a new issue