Fix Docker & KV templates for sticky

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-09-28 16:29:19 +02:00
parent 291c3b6dbc
commit 462d8b3e74
No known key found for this signature in database
GPG key ID: D808B4C167352E59
8 changed files with 59 additions and 147 deletions

View file

@ -711,12 +711,12 @@ Labels can be used on containers to override default behaviour:
- `traefik.backend.maxconn.amount=10`: set a maximum number of connections to the backend. Must be used in conjunction with the below label to take effect.
- `traefik.backend.maxconn.extractorfunc=client.ip`: set the function to be used against the request to determine what to limit maximum connections to the backend by. Must be used in conjunction with the above label to take effect.
- `traefik.backend.loadbalancer.method=drr`: override the default `wrr` load balancer algorithm
- `traefik.backend.loadbalancer.sticky=true`: enable backend sticky sessions
- `traefik.backend.circuitbreaker.expression=NetworkErrorRatio() > 0.5`: create a [circuit breaker](/basics/#backends) to be used against the backend
- `traefik.port=80`: register this port. Useful when the container exposes multiples ports.
- `traefik.protocol=https`: override the default `http` protocol
- `traefik.weight=10`: assign this weight to the container
- `traefik.enable=false`: disable this container in Træfɪk
- `traefik.stickysession=true`: enable backend sticky sessions
- `traefik.frontend.rule=Host:test.traefik.io`: override the default frontend rule (Default: `Host:{containerName}.{domain}`).
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend.
- `traefik.frontend.priority=10`: override default frontend priority
@ -811,6 +811,7 @@ Labels can be used on containers to override default behaviour:
- `traefik.backend.maxconn.amount=10`: set a maximum number of connections to the backend. Must be used in conjunction with the below label to take effect.
- `traefik.backend.maxconn.extractorfunc=client.ip`: set the function to be used against the request to determine what to limit maximum connections to the backend by. Must be used in conjunction with the above label to take effect.
- `traefik.backend.loadbalancer.method=drr`: override the default `wrr` load balancer algorithm
- `traefik.backend.loadbalancer.sticky=true`: enable backend sticky sessions
- `traefik.backend.circuitbreaker.expression=NetworkErrorRatio() > 0.5`: create a [circuit breaker](/basics/#backends) to be used against the backend
- `traefik.portIndex=1`: register port by index in the application's ports array. Useful when the application exposes multiple ports.
- `traefik.port=80`: register the explicit application port value. Cannot be used alongside `traefik.portIndex`.

148
glide.lock generated
View file

@ -1,25 +1,10 @@
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
hash: c0ac205a859d78847e21d3cd63f427ffba985755c6ae84373e4a20364ba39b05
updated: 2016-09-28T16:50:04.352639437+01:00
=======
<<<<<<< HEAD
hash: b82175c1aafff6c4e98c8ac4baea3832895c9600beac445c10af4c004982ef05
updated: 2016-09-20T16:03:26.379383173+02:00
=======
hash: f7ade4acdfd43efe6a0c1a1444776dd02d556e40bf122a495ca2fc226c880d0b
updated: 2016-08-10T11:55:40.961089942-04:00
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
hash: b82175c1aafff6c4e98c8ac4baea3832895c9600beac445c10af4c004982ef05
updated: 2016-09-28T13:05:02.84360542+02:00
>>>>>>> Fix sticky sessions Docker/Marathon labels
updated: 2016-09-30T10:57:42.336729457+02:00
imports:
- name: github.com/abbot/go-http-auth
version: cb4372376e1e00e9f6ab9ec142e029302c9e7140
- name: github.com/boltdb/bolt
version: 94c8db596809690a3f7046fa83c7b0dda13a3222
version: 5cc10bbbc5c141029940133bb33c9e969512a698
- name: github.com/BurntSushi/toml
version: 99064174e013895bbd9b025c31100bd1d9b590ca
- name: github.com/BurntSushi/ty
@ -33,7 +18,7 @@ imports:
- name: github.com/codegangsta/cli
version: 1efa31f08b9333f1bd4882d61f9d668a70cd902e
- name: github.com/codegangsta/negroni
version: 6edff56736fa7bd546812f149e8cdaae61e5a38f
version: dc6b9d037e8dab60cbfc09c61d6932537829be8b
- name: github.com/containous/flaeg
version: a731c034dda967333efce5f8d276aeff11f8ff87
- name: github.com/containous/mux
@ -51,19 +36,7 @@ imports:
subpackages:
- spew
- name: github.com/docker/distribution
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: 99cb7c0946d2f5a38015443e515dc916295064d7
=======
<<<<<<< HEAD
version: b6e0cfbdaa1ddc3a17c95142c7bf6e42c5567370
=======
version: 9000745401d186602c2ae63ffca12ed4233a968b
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
version: 9000745401d186602c2ae63ffca12ed4233a968b
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: 87917f30529e6a7fca8eaff2932424915fb11225
subpackages:
- context
- digest
@ -143,13 +116,13 @@ imports:
- types/time
- types/versions
- name: github.com/docker/go-connections
version: 0bad1a3951398f88ef4dd75fdb42af374430be89
version: 990a1a1a70b0da4c4cb70e117971a4f0babfbf1a
subpackages:
- nat
- sockets
- tlsconfig
- name: github.com/docker/go-units
version: eb879ae3e2b84e2a142af415b679ddeda47ec71c
version: f2d77a61e3c169b43402a0a1e84f06daf29b8190
- name: github.com/docker/libcompose
version: d1876c1d68527a49c0aac22a0b161acc7296b740
subpackages:
@ -168,7 +141,7 @@ imports:
- version
- yaml
- name: github.com/docker/libkv
version: aabc039ad04deb721e234f99cd1b4aa28ac71a40
version: 35d3e2084c650109e7bcc7282655b1bc8ba924ff
subpackages:
- store
- store/boltdb
@ -178,25 +151,13 @@ imports:
- name: github.com/donovanhide/eventsource
version: fd1de70867126402be23c306e1ce32828455d85b
- name: github.com/elazarl/go-bindata-assetfs
version: e1a2a7ec64b07d04ac9ebb072404fe8b7b60de1b
version: 57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2
- name: github.com/gambol99/go-marathon
version: a558128c87724cd7430060ef5aedf39f83937f55
- name: github.com/go-check/check
version: 11d3bc7aa68e238947792f30573146a3231fc0f1
version: 4f90aeace3a26ad7021961c297b22c42160c7b25
- name: github.com/gogo/protobuf
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: 89f1976ff373a3e549675d2f212c10f98b6c6316
=======
<<<<<<< HEAD
version: a11c89fbb0ad4acfa8abc4a4d5f7e27c477169b1
=======
version: a4cceea7a401a73fefafd1a21fedbd4694124a82
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
version: a4cceea7a401a73fefafd1a21fedbd4694124a82
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: e33835a643a970c11ac74f6333f5f6866387a101
subpackages:
- proto
- name: github.com/golang/glog
@ -208,39 +169,16 @@ imports:
- name: github.com/gorilla/context
version: aed02d124ae4a0e94fea4541c8effd05bf0c8296
- name: github.com/hashicorp/consul
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: d5b7530ec593f1ec2a8f8a7c145bcadafa88b572
=======
<<<<<<< HEAD
version: 67a03d57b5851011e5601ee6e7e3d05699548462
=======
version: d6aa033793a68b509d336b3bac6ebe36ac0ef818
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
version: d6aa033793a68b509d336b3bac6ebe36ac0ef818
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: fce7d75609a04eeb9d4bf41c8dc592aac18fc97d
subpackages:
- api
- name: github.com/hashicorp/go-cleanhttp
version: ad28ea4487f05916463e2423a55166280e8254b5
version: 875fb671b3ddc66f8e2f0acc33829c8cb989a38d
- name: github.com/hashicorp/serf
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: b7a120a5fc494f6dd5e858f42fd0fd4022d6320f
=======
<<<<<<< HEAD
version: 555e0dcbb180ecbd03431adc28226bb3192558bc
=======
version: a01569795d12afbdb3698739b614e057ee289fa0
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
version: a01569795d12afbdb3698739b614e057ee289fa0
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: 6c4672d66fc6312ddde18399262943e21175d831
subpackages:
- coordinate
- serf
- name: github.com/jarcoal/httpmock
version: 145b10d659265440f062c31ea15326166bae56ee
- name: github.com/libkermit/compose
@ -282,7 +220,7 @@ imports:
- name: github.com/miekg/dns
version: 5d001d020961ae1c184f9f8152fdc73810481677
- name: github.com/mitchellh/mapstructure
version: ca63d7c062ee3c9f34db231e352b60012b4fd0c1
version: d2dd0262208475919e1a362f675cfc0e7c10e905
- name: github.com/moul/http2curl
version: b1479103caacaa39319f75e7f57fc545287fca0d
- name: github.com/NYTimes/gziphandler
@ -290,25 +228,11 @@ imports:
- name: github.com/ogier/pflag
version: 45c278ab3607870051a2ea9040bb85fcb8557481
- name: github.com/opencontainers/runc
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: d9fec4c63b089ddfc267194ecb6cda58a13f072c
=======
<<<<<<< HEAD
version: 38e0df9ec67c05e73b656c02c9222f24c1683d73
>>>>>>> glide up
version: 1a81e9ab1f138c091fe5c86d0883f87716088527
subpackages:
- libcontainer/user
- name: github.com/parnurzeal/gorequest
version: 29ced6f360a5ac3823a3675b4e29fbab336cc186
=======
=======
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: 0f764571384a3ff16c6fed25ace5b7c83f0f0379
subpackages:
- libcontainer/user
- name: github.com/parnurzeal/gorequest
version: e213a02fb0082d41e66996deeaab5ae96039d913
version: 045012d33ef41ea146c1b675df9296d0dc1a212d
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
@ -322,16 +246,16 @@ imports:
- name: github.com/Sirupsen/logrus
version: a283a10442df8dc09befd873fab202bf8a253d6a
- name: github.com/streamrail/concurrent-map
version: 430cc620f036386dacc40e603921cc607f37366b
version: 65a174a3a4188c0b7099acbc6cfa0c53628d3287
- name: github.com/stretchr/objx
version: cbeaeb16a013161a98496fad62933b1d21786672
- name: github.com/stretchr/testify
version: 976c720a22c8eb4eb6a0b4348ad85ad12491a506
version: d77da356e56a7428ad25149ca77381849a6a5232
subpackages:
- assert
- mock
- name: github.com/thoas/stats
version: 152b5d051953fdb6e45f14b6826962aadc032324
version: 79b768ff1780f4e5b0ed132e192bfeefe9f85a9c
- name: github.com/tv42/zbase32
version: 03389da7e0bf9844767f82690f4d68fc097a1306
- name: github.com/ugorji/go
@ -339,7 +263,7 @@ imports:
subpackages:
- codec
- name: github.com/unrolled/render
version: 7bc415efc1b94ad17b0fc642cb50b3e2465027e7
version: 198ad4d8b8a4612176b804ca10555b222a086b40
- name: github.com/vdemeester/docker-events
version: be74d4929ec1ad118df54349fda4b0cba60f849b
- name: github.com/vdemeester/shakers
@ -361,11 +285,7 @@ imports:
- name: github.com/vulcand/route
version: cb89d787ddbb1c5849a7ac9f79004c1fd12a4a32
- name: github.com/vulcand/vulcand
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
version: 643ca8acff8386e3b276f6feb8ba9b5893dbc4a2
=======
version: 28a4e5c0892167589737b95ceecbcef00295be50
>>>>>>> Fix sticky sessions Docker/Marathon labels
subpackages:
- conntracker
- plugin
@ -395,27 +315,11 @@ imports:
- name: gopkg.in/fsnotify.v1
version: a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb
- name: gopkg.in/mgo.v2
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
version: 22287bab4379e1fbf6002fb4eb769888f3fb224c
subpackages:
- bson
- name: gopkg.in/square/go-jose.v1
<<<<<<< 3d7c44735a6fe792ad7fc9f074034a260e53bb0d
version: aa2e30fdd1fe9dd3394119af66451ae790d50e0d
=======
<<<<<<< HEAD
version: 139276ceb5afbf13e636c44e9382f0ca75c12ba3
=======
version: a3927f83df1b1516f9e9dec71839c93e6bcf1db0
>>>>>>> 2848e10... glide up
>>>>>>> glide up
=======
version: 29cc868a5ca65f401ff318143f9408d02f4799cc
subpackages:
- bson
- name: gopkg.in/square/go-jose.v1
version: a3927f83df1b1516f9e9dec71839c93e6bcf1db0
>>>>>>> Fix sticky sessions Docker/Marathon labels
version: e3f973b66b91445ec816dd7411ad1b6495a5a2fc
subpackages:
- cipher
- json
@ -433,13 +337,9 @@ testImports:
- name: github.com/libkermit/docker-check
version: cbe0ef03b3d23070eac4d00ba8828f2cc7f7e5a3
- name: github.com/spf13/pflag
<<<<<<< df225d9170aa2efb251cb74f0a58b2952315fe2b
version: 08b1a584251b5b62f458943640fc8ebd4d50aaa5
=======
version: 5644820622454e71517561946e3d94b9f9db6842
>>>>>>> Fix sticky sessions Docker/Marathon labels
- name: github.com/vbatts/tar-split
version: bd4c5d64c3e9297f410025a3b1bd0c58f659e721
version: 6810cedb21b2c3d0b9bb8f9af12ff2dc7a2f14df
subpackages:
- archive/tar
- tar/asm
@ -449,4 +349,4 @@ testImports:
- name: github.com/xeipuuv/gojsonreference
version: e02fc20de94c78484cd5ffb007f8af96be030a45
- name: github.com/xeipuuv/gojsonschema
version: e4f482d0deea5bfc0522ab4582c5fdbd2edc98ad
version: 00f9fafb54d2244d291b86ab63d12c38bd5c3886

View file

@ -262,19 +262,27 @@ func (provider *Docker) loadDockerConfig(containersInspected []dockerData) *type
}, containersInspected).([]dockerData)
frontends := map[string][]dockerData{}
backends := map[string]dockerData{}
servers := map[string][]dockerData{}
for _, container := range filteredContainers {
frontendName := provider.getFrontendName(container)
frontends[frontendName] = append(frontends[frontendName], container)
frontends[frontendName] = append(frontends[frontendName], container)
backendName := provider.getBackend(container)
backends[backendName] = container
servers[backendName] = append(servers[backendName], container)
}
templateObjects := struct {
Containers []dockerData
Frontends map[string][]dockerData
Backends map[string]dockerData
Servers map[string][]dockerData
Domain string
}{
filteredContainers,
frontends,
backends,
servers,
provider.Domain,
}

View file

@ -940,7 +940,6 @@ func TestDockerLoadDockerConfig(t *testing.T) {
},
},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{Sticky: false, Method: ""},
},
},
},
@ -1027,7 +1026,6 @@ func TestDockerLoadDockerConfig(t *testing.T) {
},
},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{Sticky: false, Method: ""},
},
},
},

View file

@ -107,7 +107,6 @@ func TestMarathonLoadConfig(t *testing.T) {
},
},
CircuitBreaker: nil,
LoadBalancer: &types.LoadBalancer{Sticky: false},
},
},
},

View file

@ -546,12 +546,11 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
}
stickysession := configuration.Backends[frontend.Backend].LoadBalancer.Sticky
var cookiename string
cookiename := "_TRAEFIK_BACKEND"
var sticky *roundrobin.StickySession
if stickysession {
sticky = roundrobin.NewStickySession(cookiename)
cookiename = "_TRAEFIK_BACKEND"
}
switch lbMethod {

View file

@ -1,24 +1,29 @@
[backends]{{range .Containers}}
{{if hasCircuitBreakerLabel .}}
[backends.backend-{{getBackend .}}.circuitbreaker]
expression = "{{getCircuitBreakerExpression .}}"
{{$backendServers := .Servers}}
[backends]{{range $backendName, $backend := .Backends}}
{{if hasCircuitBreakerLabel $backend}}
[backends.backend-{{$backendName}}.circuitbreaker]
expression = "{{getCircuitBreakerExpression $backend}}"
{{end}}
{{if hasLoadBalancerLabel .}}
[backends.backend-{{getBackend .}}.loadbalancer]
method = "{{getLoadBalancerMethod .}}"
sticky = {{getSticky . }}
{{if hasLoadBalancerLabel $backend}}
[backends.backend-{{$backendName}}.loadbalancer]
method = "{{getLoadBalancerMethod $backend}}"
sticky = {{getSticky $backend}}
{{end}}
{{if hasMaxConnLabels .}}
[backends.backend-{{getBackend .}}.maxconn]
amount = {{getMaxConnAmount . }}
extractorfunc = "{{getMaxConnExtractorFunc . }}"
{{if hasMaxConnLabels $backend}}
[backends.backend-{{$backendName}}.maxconn]
amount = {{getMaxConnAmount $backend}}
extractorfunc = "{{getMaxConnExtractorFunc $backend}}"
{{end}}
{{$servers := index $backendServers $backendName}}
{{range $serverName, $server := $servers}}
[backends.backend-{{$backendName}}.servers.server-{{$server.Name | replace "/" "" | replace "." "-"}}]
url = "{{getProtocol $server}}://{{getIPAddress $server}}:{{getPort $server}}"
weight = {{getWeight $server}}
{{end}}
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
url = "{{getProtocol .}}://{{getIPAddress .}}:{{getPort .}}"
weight = {{getWeight .}}
{{end}}
[frontends]{{range $frontend, $containers := .Frontends}}

View file

@ -12,9 +12,11 @@
{{end}}
{{$loadBalancer := Get "" . "/loadbalancer/" "method"}}
{{$sticky := Get "false" . "/loadbalancer/" "sticky"}}
{{with $loadBalancer}}
[backends."{{Last $backend}}".loadBalancer]
method = "{{$loadBalancer}}"
sticky = {{$sticky}}
{{end}}
{{$maxConnAmt := Get "" . "/maxconn/" "amount"}}