Fix constraints and add doc

This commit is contained in:
Emile Vauge 2016-09-20 16:56:29 +02:00
parent 89fc835bb2
commit a882a9d79f
No known key found for this signature in database
GPG key ID: D808B4C167352E59
4 changed files with 89 additions and 44 deletions

View file

@ -85,25 +85,23 @@ Supported filters:
``` ```
# Constraints definition # Constraints definition
# #
# Optional # Optional
# #
# Simple matching constraint # Simple matching constraint
# constraints = ["tag==api"] # constraints = ["tag==api"]
#
# Simple mismatching constraint # Simple mismatching constraint
# constraints = ["tag!=api"] # constraints = ["tag!=api"]
#
# Globbing # Globbing
# constraints = ["tag==us-*"] # constraints = ["tag==us-*"]
#
# Backend-specific constraint # Backend-specific constraint
# [consulCatalog] # [consulCatalog]
# endpoint = 127.0.0.1:8500 # endpoint = 127.0.0.1:8500
# constraints = ["tag==api"] # constraints = ["tag==api"]
#
# Multiple constraints # Multiple constraints
# - "tag==" must match with at least one tag # - "tag==" must match with at least one tag
# - "tag!=" must match with none of tags # - "tag!=" must match with none of tags
@ -891,13 +889,6 @@ prefix = "traefik"
# cert = "/etc/ssl/consul.crt" # cert = "/etc/ssl/consul.crt"
# key = "/etc/ssl/consul.key" # key = "/etc/ssl/consul.key"
# insecureskipverify = true # insecureskipverify = true
# Constraint on ConsulKV tags
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having a key "/traefik/backends/backend1/servers/server1/tags" equal to "api,helloworld"
``` ```
Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure. Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure.
@ -1001,13 +992,6 @@ prefix = "/traefik"
# cert = "/etc/ssl/etcd.crt" # cert = "/etc/ssl/etcd.crt"
# key = "/etc/ssl/etcd.key" # key = "/etc/ssl/etcd.key"
# insecureskipverify = true # insecureskipverify = true
# Constraint on Etcd tags
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having a key "/traefik/backends/backend1/servers/server1/tags" equal to "api,helloworld"
``` ```
Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure. Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure.
@ -1051,13 +1035,6 @@ prefix = "/traefik"
# Optional # Optional
# #
# filename = "zookeeper.tmpl" # filename = "zookeeper.tmpl"
# Constraint on Zookeeper tags
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having a key "/traefik/backends/backend1/servers/server1/tags" equal to "api,helloworld"
``` ```
Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure. Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure.
@ -1100,13 +1077,6 @@ prefix = "/traefik"
# Optional # Optional
# #
# filename = "boltdb.tmpl" # filename = "boltdb.tmpl"
# Constraint on BoltDB tags
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having a key "/traefik/backends/backend1/servers/server1/tags" equal to "api,helloworld"
``` ```
Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure. Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on traefik KV structure.

20
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 7382685091734eeeef590d8d298600abfaa21c40c8714ef570b8006e4f8cc846 hash: b82175c1aafff6c4e98c8ac4baea3832895c9600beac445c10af4c004982ef05
updated: 2016-08-19T14:15:17.22440385+02:00 updated: 2016-09-20T16:03:26.379383173+02:00
imports: imports:
- name: github.com/abbot/go-http-auth - name: github.com/abbot/go-http-auth
version: cb4372376e1e00e9f6ab9ec142e029302c9e7140 version: cb4372376e1e00e9f6ab9ec142e029302c9e7140
@ -11,8 +11,8 @@ imports:
version: 6add9cd6ad42d389d6ead1dde60b4ad71e46fd74 version: 6add9cd6ad42d389d6ead1dde60b4ad71e46fd74
subpackages: subpackages:
- fun - fun
- name: github.com/cenkalti/backoff - name: github.com/cenk/backoff
version: cdf48bbc1eb78d1349cbda326a4a037f7ba565c6 version: 8edc80b07f38c27352fb186d971c628a6c32552b
- name: github.com/codahale/hdrhistogram - name: github.com/codahale/hdrhistogram
version: f8ad88b59a584afeee9d334eff879b104439117b version: f8ad88b59a584afeee9d334eff879b104439117b
- name: github.com/codegangsta/cli - name: github.com/codegangsta/cli
@ -36,7 +36,7 @@ imports:
subpackages: subpackages:
- spew - spew
- name: github.com/docker/distribution - name: github.com/docker/distribution
version: 2b72dd3927b2958160a2336f16145c0c421aa6a4 version: b6e0cfbdaa1ddc3a17c95142c7bf6e42c5567370
subpackages: subpackages:
- context - context
- digest - digest
@ -141,7 +141,7 @@ imports:
- version - version
- yaml - yaml
- name: github.com/docker/libkv - name: github.com/docker/libkv
version: 35d3e2084c650109e7bcc7282655b1bc8ba924ff version: 3fce6a0f26e07da3eac45796a8e255547a47a750
subpackages: subpackages:
- store - store
- store/boltdb - store/boltdb
@ -157,7 +157,7 @@ imports:
- name: github.com/go-check/check - name: github.com/go-check/check
version: 4f90aeace3a26ad7021961c297b22c42160c7b25 version: 4f90aeace3a26ad7021961c297b22c42160c7b25
- name: github.com/gogo/protobuf - name: github.com/gogo/protobuf
version: 6abcf94fd4c97dcb423fdafd42fe9f96ca7e421b version: a11c89fbb0ad4acfa8abc4a4d5f7e27c477169b1
subpackages: subpackages:
- proto - proto
- name: github.com/golang/glog - name: github.com/golang/glog
@ -219,13 +219,13 @@ imports:
- name: github.com/miekg/dns - name: github.com/miekg/dns
version: 5d001d020961ae1c184f9f8152fdc73810481677 version: 5d001d020961ae1c184f9f8152fdc73810481677
- name: github.com/mitchellh/mapstructure - name: github.com/mitchellh/mapstructure
version: d2dd0262208475919e1a362f675cfc0e7c10e905 version: ca63d7c062ee3c9f34db231e352b60012b4fd0c1
- name: github.com/moul/http2curl - name: github.com/moul/http2curl
version: b1479103caacaa39319f75e7f57fc545287fca0d version: b1479103caacaa39319f75e7f57fc545287fca0d
- name: github.com/ogier/pflag - name: github.com/ogier/pflag
version: 45c278ab3607870051a2ea9040bb85fcb8557481 version: 45c278ab3607870051a2ea9040bb85fcb8557481
- name: github.com/opencontainers/runc - name: github.com/opencontainers/runc
version: fb221651e5120cd287a76c7c1b6c877520fbd034 version: 38e0df9ec67c05e73b656c02c9222f24c1683d73
subpackages: subpackages:
- libcontainer/user - libcontainer/user
- name: github.com/parnurzeal/gorequest - name: github.com/parnurzeal/gorequest
@ -252,7 +252,7 @@ imports:
- assert - assert
- mock - mock
- name: github.com/thoas/stats - name: github.com/thoas/stats
version: 79b768ff1780f4e5b0ed132e192bfeefe9f85a9c version: 152b5d051953fdb6e45f14b6826962aadc032324
- name: github.com/tv42/zbase32 - name: github.com/tv42/zbase32
version: 501572607d0273fc75b3b261fa4904d63f6ffa0e version: 501572607d0273fc75b3b261fa4904d63f6ffa0e
- name: github.com/ugorji/go - name: github.com/ugorji/go

View file

@ -62,6 +62,32 @@
# #
# defaultEntryPoints = ["http", "https"] # defaultEntryPoints = ["http", "https"]
# Constraints definition
#
# Optional
#
# Simple matching constraint
# constraints = ["tag==api"]
#
# Simple mismatching constraint
# constraints = ["tag!=api"]
#
# Globbing
# constraints = ["tag==us-*"]
#
# Backend-specific constraint
# [consulCatalog]
# endpoint = 127.0.0.1:8500
# constraints = ["tag==api"]
#
# Multiple constraints
# - "tag==" must match with at least one tag
# - "tag!=" must match with none of tags
# constraints = ["tag!=us-*", "tag!=asia-*"]
# [consulCatalog]
# endpoint = 127.0.0.1:8500
# constraints = ["tag==api", "tag!=v*-beta"]
# Enable ACME (Let's Encrypt): automatic SSL # Enable ACME (Let's Encrypt): automatic SSL
# #
# Optional # Optional
@ -370,6 +396,14 @@
# key = "/etc/ssl/docker.key" # key = "/etc/ssl/docker.key"
# insecureskipverify = true # insecureskipverify = true
# Constraints
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having the label "traefik.tags" set to "api,helloworld"
# ex: $ docker run -d -P --label traefik.tags=api,helloworld emilevauge/whoami
################################################################ ################################################################
# Mesos/Marathon configuration backend # Mesos/Marathon configuration backend
@ -578,6 +612,40 @@
# key = "/etc/ssl/consul.key" # key = "/etc/ssl/consul.key"
# insecureskipverify = true # insecureskipverify = true
################################################################
# Consul Catalog configuration backend
################################################################
# Enable Consul Catalog configuration backend
#
# Optional
#
# [consulCatalog]
# Consul server endpoint
#
# Required
#
# endpoint = "127.0.0.1:8500"
# Default domain used.
#
# Optional
#
# domain = "consul.localhost"
# Prefix for Consul catalog tags
#
# Optional
#
# prefix = "traefik"
# Constraints
#
# Optional
#
# constraints = ["tag==api", "tag==he*ld"]
# Matching with containers having this tag: "traefik.tags=api,helloworld"
################################################################ ################################################################
# Etcd configuration backend # Etcd configuration backend

View file

@ -139,6 +139,13 @@ func (c *Constraint) String() string {
return c.Key + "!=" + c.Regex return c.Key + "!=" + c.Regex
} }
// UnmarshalText define how unmarshal in TOML parsing
func (c *Constraint) UnmarshalText(text []byte) error {
constraint, err := NewConstraint(string(text))
*c = *constraint
return err
}
// MatchConstraintWithAtLeastOneTag tests a constraint for one single service // MatchConstraintWithAtLeastOneTag tests a constraint for one single service
func (c *Constraint) MatchConstraintWithAtLeastOneTag(tags []string) bool { func (c *Constraint) MatchConstraintWithAtLeastOneTag(tags []string) bool {
for _, tag := range tags { for _, tag := range tags {