This commit is contained in:
emile 2015-09-10 16:14:08 +02:00
parent 46ef489b03
commit 4dc5b34122
8 changed files with 40 additions and 11 deletions

View file

@ -2,7 +2,6 @@
* Godoc * Godoc
* Weights * Weights
* Licence * Licence
* GraceTimeout
* Filter no exposed port apps * Filter no exposed port apps
* Filter træfik.enabled=false apps * Filter træfik.enabled=false apps
* Add træfik.indlude all/enabled policy * Add træfik.indlude all/enabled policy
@ -14,3 +13,5 @@
* Smart configuration diff * Smart configuration diff
* README * README
* ~~GraceTimeout~~

View file

@ -24,6 +24,7 @@ type Backend struct {
type Server struct { type Server struct {
Url string Url string
Weight int
} }
type Rule struct { type Rule struct {

View file

@ -37,6 +37,14 @@ var DockerFuncMap = template.FuncMap{
} }
return "" 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 { "replace": func(s1 string, s2 string, s3 string) string {
return strings.Replace(s3, s1, s2, -1) return strings.Replace(s3, s1, s2, -1)
}, },

View file

@ -1,6 +1,7 @@
[backends]{{range .Containers}} [backends]{{range .Containers}}
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}] [backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}" url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}"
weight = {{getWeight .}}
{{end}} {{end}}
[routes]{{range $host, $containers := .Hosts}} [routes]{{range $host, $containers := .Hosts}}

View file

@ -34,6 +34,14 @@ var MarathonFuncMap = template.FuncMap{
} }
return strings.Replace(application.ID, "/", "", 1) 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 { "replace": func(s1 string, s2 string, s3 string) string {
return strings.Replace(s3, s1, s2, -1) return strings.Replace(s3, s1, s2, -1)
}, },

View file

@ -1,6 +1,13 @@
{{$apps := .Applications}}
[backends]{{range .Tasks}} [backends]{{range .Tasks}}
[backends.backend{{.AppID | replace "/" "-"}}.servers.server-{{.ID | replace "." "-"}}] [backends.backend{{.AppID | replace "/" "-"}}.servers.server-{{.ID | replace "." "-"}}]
url = "http://{{.Host}}:{{getPort .}}" url = "http://{{.Host}}:{{getPort .}}"
{{$appID := .AppID}}
{{range $apps}}
{{if eq $appID .ID}}
weight = {{getWeight .}}
{{end}}
{{end}}
{{end}} {{end}}
[routes]{{range .Applications}} [routes]{{range .Applications}}

View file

@ -137,7 +137,7 @@ func LoadConfig(configuration *Configuration) *mux.Router {
for serverName, server := range configuration.Backends[route.Backend].Servers { for serverName, server := range configuration.Backends[route.Backend].Servers {
log.Println("Creating server", serverName) log.Println("Creating server", serverName)
url, _ := url.Parse(server.Url) url, _ := url.Parse(server.Url)
rb.UpsertServer(url) rb.UpsertServer(url, roundrobin.Weight(server.Weight))
} }
backends[route.Backend]=lb backends[route.Backend]=lb
}else { }else {

View file

@ -1,35 +1,38 @@
port = ":8001" port = ":8001"
graceTimeOut = 10 graceTimeOut = 10
#[docker] # [docker]
#endpoint = "unix:///var/run/docker.sock" # endpoint = "unix:///var/run/docker.sock"
#watch = true # watch = true
#domain = "toto.fr" # domain = "toto.fr"
#filename = "docker.tmpl" # filename = "docker.tmpl"
[marathon] [marathon]
endpoint = "http://127.0.0.1:8080" endpoint = "http://127.0.0.1:8080"
networkInterface = "eth0"
watch = true watch = true
domain = "toto.fr" domain = "toto.fr"
filename = "marathon.tmpl" filename = "marathon.tmpl"
networkInterface = "eth0"
[web] [web]
address = ":8010" address = ":8010"
#[file] # [file]
#filename = "rules.toml" # filename = "rules.toml"
#watch = true # watch = true
[backends] [backends]
[backends.backend1] [backends.backend1]
[backends.backend1.servers.server1] [backends.backend1.servers.server1]
url = "http://172.17.0.2:80" url = "http://172.17.0.2:80"
weight = 10
[backends.backend1.servers.server2] [backends.backend1.servers.server2]
url = "http://172.17.0.3:80" url = "http://172.17.0.3:80"
weight = 1
[backends.backend2] [backends.backend2]
[backends.backend2.servers.server1] [backends.backend2.servers.server1]
url = "http://172.17.0.2:80" url = "http://172.17.0.2:80"
weight = 100
[routes] [routes]
[routes.route1] [routes.route1]