Weights
This commit is contained in:
parent
46ef489b03
commit
4dc5b34122
8 changed files with 40 additions and 11 deletions
|
@ -2,7 +2,6 @@
|
|||
* Godoc
|
||||
* Weights
|
||||
* Licence
|
||||
* GraceTimeout
|
||||
* Filter no exposed port apps
|
||||
* Filter træfik.enabled=false apps
|
||||
* Add træfik.indlude all/enabled policy
|
||||
|
@ -14,3 +13,5 @@
|
|||
* Smart configuration diff
|
||||
* README
|
||||
|
||||
|
||||
* ~~GraceTimeout~~
|
|
@ -24,6 +24,7 @@ type Backend struct {
|
|||
|
||||
type Server struct {
|
||||
Url string
|
||||
Weight int
|
||||
}
|
||||
|
||||
type Rule struct {
|
||||
|
|
|
@ -37,6 +37,14 @@ var DockerFuncMap = template.FuncMap{
|
|||
}
|
||||
return ""
|
||||
},
|
||||
"getWeight": func(container docker.Container) string {
|
||||
for key, value := range container.Config.Labels {
|
||||
if (key == "træfik.weight") {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[backends]{{range .Containers}}
|
||||
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
|
||||
url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}"
|
||||
weight = {{getWeight .}}
|
||||
{{end}}
|
||||
|
||||
[routes]{{range $host, $containers := .Hosts}}
|
||||
|
|
|
@ -34,6 +34,14 @@ var MarathonFuncMap = template.FuncMap{
|
|||
}
|
||||
return strings.Replace(application.ID, "/", "", 1)
|
||||
},
|
||||
"getWeight": func(application marathon.Application) string {
|
||||
for key, value := range application.Labels {
|
||||
if (key == "træfik.weight") {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return "0"
|
||||
},
|
||||
"replace": func(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
},
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
{{$apps := .Applications}}
|
||||
[backends]{{range .Tasks}}
|
||||
[backends.backend{{.AppID | replace "/" "-"}}.servers.server-{{.ID | replace "." "-"}}]
|
||||
url = "http://{{.Host}}:{{getPort .}}"
|
||||
{{$appID := .AppID}}
|
||||
{{range $apps}}
|
||||
{{if eq $appID .ID}}
|
||||
weight = {{getWeight .}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
[routes]{{range .Applications}}
|
||||
|
|
|
@ -137,7 +137,7 @@ func LoadConfig(configuration *Configuration) *mux.Router {
|
|||
for serverName, server := range configuration.Backends[route.Backend].Servers {
|
||||
log.Println("Creating server", serverName)
|
||||
url, _ := url.Parse(server.Url)
|
||||
rb.UpsertServer(url)
|
||||
rb.UpsertServer(url, roundrobin.Weight(server.Weight))
|
||||
}
|
||||
backends[route.Backend]=lb
|
||||
}else {
|
||||
|
|
|
@ -9,10 +9,10 @@ graceTimeOut = 10
|
|||
|
||||
[marathon]
|
||||
endpoint = "http://127.0.0.1:8080"
|
||||
networkInterface = "eth0"
|
||||
watch = true
|
||||
domain = "toto.fr"
|
||||
filename = "marathon.tmpl"
|
||||
networkInterface = "eth0"
|
||||
|
||||
[web]
|
||||
address = ":8010"
|
||||
|
@ -25,11 +25,14 @@ address = ":8010"
|
|||
[backends.backend1]
|
||||
[backends.backend1.servers.server1]
|
||||
url = "http://172.17.0.2:80"
|
||||
weight = 10
|
||||
[backends.backend1.servers.server2]
|
||||
url = "http://172.17.0.3:80"
|
||||
weight = 1
|
||||
[backends.backend2]
|
||||
[backends.backend2.servers.server1]
|
||||
url = "http://172.17.0.2:80"
|
||||
weight = 100
|
||||
|
||||
[routes]
|
||||
[routes.route1]
|
||||
|
|
Loading…
Reference in a new issue