From aacedcc4b3d92601797296fa64036c21f40413af Mon Sep 17 00:00:00 2001 From: Advait Shinde Date: Mon, 15 Feb 2016 18:14:21 -0500 Subject: [PATCH 1/3] Implement `/traefik/alias` for KV stores. --- provider/kv.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/provider/kv.go b/provider/kv.go index c8c674721..898d6d240 100644 --- a/provider/kv.go +++ b/provider/kv.go @@ -70,7 +70,8 @@ func (provider *Kv) loadConfig() *types.Configuration { templateObjects := struct { Prefix string }{ - provider.Prefix, + // Allow `/traefik/alias` to superesede `provider.Prefix` + strings.TrimSuffix(provider.get(provider.Prefix, provider.Prefix+"/alias"), "/"), } var KvFuncMap = template.FuncMap{ "List": provider.list, From 348ab794c941ef8c4fb60621a8a8280c8352e940 Mon Sep 17 00:00:00 2001 From: Advait Shinde Date: Mon, 15 Feb 2016 18:46:03 -0500 Subject: [PATCH 2/3] Add documentation for `/traefik/alias`. --- docs/index.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/index.md b/docs/index.md index 0ec4ebc92..f6f39fc40 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,6 +15,7 @@ ___ - [Etcd backend](#etcd) - [Zookeeper backend](#zk) - [Boltdb backend](#boltdb) +- [Atomic configuration changes](#atomicconfig) - [Benchmarks](#benchmarks) @@ -946,6 +947,44 @@ Træfɪk can be configured to use BoltDB as a backend configuration: # filename = "boltdb.tmpl" ``` +## Atomic configuration changes + +The [Etcd](https://github.com/coreos/etcd/issues/860) and [Consul](https://github.com/hashicorp/consul/issues/886) backends do not support updating multiple keys atomically. As a result, it may be possible for Træfɪk to read an intermediate configuration state despite judicious use of the `--providersThrottleDuration` flag. To solve this problem, Træfɪk supports a special key called `/traefik/alias`. If set, Træfɪk use the value as an alternative key prefix. + +Given the key structure below, Træfɪk will use the `http://172.17.0.2:80` as its only backend (frontend keys have been omitted for brevity). + +| Key | Value | +|-------------------------------------------------------------------------|-----------------------------| +| `/traefik/alias` | `/traefik_configurations/1` | +| `/traefik_configurations/1/backends/backend1/servers/server1/url` | `http://172.17.0.2:80` | +| `/traefik_configurations/1/backends/backend1/servers/server1/weight` | `10` | + +When an atomic configuration change is required, you may write a new configuration at an alternative prefix. Here, although the `/traefik_configurations/2/...` keys have been set, the old configuration is still active because the `/traefik/alias` key still points to `/traefik_configurations/1`: + +| Key | Value | +|-------------------------------------------------------------------------|-----------------------------| +| `/traefik/alias` | `/traefik_configurations/1` | +| `/traefik_configurations/1/backends/backend1/servers/server1/url` | `http://172.17.0.2:80` | +| `/traefik_configurations/1/backends/backend1/servers/server1/weight` | `10` | +| `/traefik_configurations/2/backends/backend1/servers/server1/url` | `http://172.17.0.2:80` | +| `/traefik_configurations/2/backends/backend1/servers/server1/weight` | `5` | +| `/traefik_configurations/2/backends/backend1/servers/server2/url` | `http://172.17.0.3:80` | +| `/traefik_configurations/2/backends/backend1/servers/server2/weight` | `5` | + +Once the `/traefik/alias` key is updated, the new `/traefik_configurations/2` configuration becomes active atomically. Here, we have a 50% balance between the `http://172.17.0.3:80` and the `http://172.17.0.4:80` hosts while no traffic is sent to the `172.17.0.2:80` host: + +| Key | Value | +|-------------------------------------------------------------------------|-----------------------------| +| `/traefik/alias` | `/traefik_configurations/2` | +| `/traefik_configurations/1/backends/backend1/servers/server1/url` | `http://172.17.0.2:80` | +| `/traefik_configurations/1/backends/backend1/servers/server1/weight` | `10` | +| `/traefik_configurations/2/backends/backend1/servers/server1/url` | `http://172.17.0.3:80` | +| `/traefik_configurations/2/backends/backend1/servers/server1/weight` | `5` | +| `/traefik_configurations/2/backends/backend1/servers/server2/url` | `http://172.17.0.4:80` | +| `/traefik_configurations/2/backends/backend1/servers/server2/weight` | `5` | + +Note that TRAEFIK *will not watch for key changes in the `/traefik_configurations` prefix*. It will only watch for changes in the `/traefik` prefix. Further, if the `/traefik/alias` key is set, all other sibling keys with the `/traefik` prefix are ignored. + ## Benchmarks From f1c1eed4374a73bb5f6bc5ae5a20f07c85fb693e Mon Sep 17 00:00:00 2001 From: Advait Shinde Date: Tue, 16 Feb 2016 11:55:42 -0500 Subject: [PATCH 3/3] Fix typo in documentation --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index f6f39fc40..e02d2e73f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -983,7 +983,7 @@ Once the `/traefik/alias` key is updated, the new `/traefik_configurations/2` co | `/traefik_configurations/2/backends/backend1/servers/server2/url` | `http://172.17.0.4:80` | | `/traefik_configurations/2/backends/backend1/servers/server2/weight` | `5` | -Note that TRAEFIK *will not watch for key changes in the `/traefik_configurations` prefix*. It will only watch for changes in the `/traefik` prefix. Further, if the `/traefik/alias` key is set, all other sibling keys with the `/traefik` prefix are ignored. +Note that Træfɪk *will not watch for key changes in the `/traefik_configurations` prefix*. It will only watch for changes in the `/traefik` prefix. Further, if the `/traefik/alias` key is set, all other sibling keys with the `/traefik` prefix are ignored. ## Benchmarks