kv: Ignore backend servers with no url

Currently with a kv tree like:
/traefik/backends/b1/servers/ẁeb1
/traefik/backends/b1/servers/web2
/traefik/backends/b1/servers/web2/url
Traefik would try to forward traffic to web1, which is impossible as
traefik doesn't know the url of web1.

This commit solve that, by ignoring backend server with no url "key"
when generating the config.

This is very useful, for people who use etcd TTL feature. They can then
just "renew" the url key every X second, and if the server goes down, it
is automatic removed from traefik after the TTL.
This commit is contained in:
Kristian Klausen 2017-02-27 00:25:54 +01:00 committed by Emile Vauge
parent 69c31276f2
commit 020a8e31ab
No known key found for this signature in database
GPG key ID: D808B4C167352E59

View file

@ -162,6 +162,9 @@ func (provider *Kv) list(keys ...string) []string {
func (provider *Kv) listServers(backend string) []string {
serverNames := provider.list(backend, "/servers/")
return fun.Filter(func(serverName string) bool {
if _, err := provider.kvclient.Get(fmt.Sprint(serverName, "/url")); err != nil {
return false
}
return provider.checkConstraints(serverName, "/tags")
}, serverNames).([]string)
}