rework loadbalancer support

This commit is contained in:
Julien Salleyron 2019-06-05 22:18:06 +02:00 committed by Traefiker Bot
parent b143101f82
commit 518a37e776
86 changed files with 339 additions and 1055 deletions

View file

@ -134,5 +134,4 @@ labels:
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:80"
Weight = 1
```

View file

@ -92,7 +92,6 @@ labels:
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:80"
Weight = 1
```
## Advanced Configuration

View file

@ -232,7 +232,7 @@ Every [Router](../routing/routers/index.md) parameter can be updated this way.
### Services
To update the configuration of the Service automatically attached to the container, add labels starting with `traefik.http.services.{name-of-your-choice}.`, followed by the option you want to change. For example, to change the load balancer method, you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.method=drr`.
To update the configuration of the Service automatically attached to the container, add labels starting with `traefik.http.services.{name-of-your-choice}.`, followed by the option you want to change. For example, to change the passhostheader behavior, you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.passhostheader=false`.
Every [Service](../routing/services/index.md) parameter can be updated this way.

View file

@ -44,13 +44,10 @@ You can write these configuration elements:
[http.services]
[http.services.service-foo]
[http.services.service-foo.LoadBalancer]
method = "wrr"
[[http.services.service-foo.LoadBalancer.Servers]]
url = "http://foo/"
weight = 30
[[http.services.service-foo.LoadBalancer.Servers]]
url = "http://bar/"
weight = 70
```
## Provider Configuration Options

View file

@ -262,7 +262,7 @@ Every [Router](../routing/routers/index.md) parameter can be updated this way.
To update the configuration of the Service automatically attached to the container,
add labels starting with `traefik.HTTP.Services.{service-name-of-your-choice}.`, followed by the option you want to change.
For example, to change the load balancer method, you'd add the label `traefik.HTTP.Services.Servicename.LoadBalancer.Method=drr`.
For example, to change the passhostheader behavior, you'd add the label `traefik.HTTP.Services.Servicename.LoadBalancer.PassHostHeader=false`.
Every [Service](../routing/services/index.md) parameter can be updated this way.

View file

@ -152,8 +152,8 @@ Every [Router](../routing/routers/index.md) parameter can be updated this way.
### Services
To update the configuration of the Service automatically attached to the container, add labels starting with `traefik.http.services.{name-of-your-choice}.`,
followed by the option you want to change. For example, to change the load balancer method,
you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.method=drr`.
followed by the option you want to change. For example, to change the passhostheader behavior,
you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.passhostheader=false`.
Every [Service](../routing/services/index.md) parameter can be updated this way.

View file

@ -172,19 +172,16 @@
[HTTP.Services]
[HTTP.Services.Service0]
[HTTP.Services.Service0.LoadBalancer]
Method = "foobar"
PassHostHeader = true
[[HTTP.Services.Service0.LoadBalancer.Servers]]
URL = "foobar"
Weight = 42
[HTTP.Services.Service0.LoadBalancer.Stickiness]
CookieName = "foobar"
[[HTTP.Services.Service0.LoadBalancer.Servers]]
URL = "foobar"
Weight = 42
[HTTP.Services.Service0.LoadBalancer.HealthCheck]
Scheme = "foobar"
@ -214,15 +211,12 @@
[TCP.Services.TCPService0]
[TCP.Services.TCPService0.LoadBalancer]
Method = "foobar"
[[TCP.Services.TCPService0.LoadBalancer.Servers]]
Address = "foobar"
Weight = 42
[[TCP.Services.TCPService0.LoadBalancer.Servers]]
Address = "foobar"
Weight = 42
[[TLS]]
Stores = ["foobar", "foobar"]

View file

@ -122,12 +122,10 @@ labels:
- "traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Port=42"
- "traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Scheme=foobar"
- "traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout=foobar"
- "traefik.HTTP.Services.Service0.LoadBalancer.Method=foobar"
- "traefik.HTTP.Services.Service0.LoadBalancer.PassHostHeader=true"
- "traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval=foobar"
- "traefik.HTTP.Services.Service0.LoadBalancer.server.Port=8080"
- "traefik.HTTP.Services.Service0.LoadBalancer.server.Scheme=foobar"
- "traefik.HTTP.Services.Service0.LoadBalancer.server.Weight=42"
- "traefik.HTTP.Services.Service0.LoadBalancer.Stickiness.CookieName=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name0=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name1=foobar"
@ -137,12 +135,10 @@ labels:
- "traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Port=42"
- "traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Scheme=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.Method=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.PassHostHeader=true"
- "traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.server.Port=8080"
- "traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme=foobar"
- "traefik.HTTP.Services.Service1.LoadBalancer.server.Weight=42"
- "traefik.TCP.Routers.Router0.Rule=foobar"
- "traefik.TCP.Routers.Router0.EntryPoints=foobar, fiibar"
- "traefik.TCP.Routers.Router0.Service=foobar"
@ -151,9 +147,5 @@ labels:
- "traefik.TCP.Routers.Router1.EntryPoints=foobar, fiibar"
- "traefik.TCP.Routers.Router1.Service=foobar"
- "traefik.TCP.Routers.Router1.TLS.Passthrough=false"
- "traefik.TCP.Services.Service0.LoadBalancer.Method=foobar"
- "traefik.TCP.Services.Service0.LoadBalancer.server.Port=42"
- "traefik.TCP.Services.Service0.LoadBalancer.server.Weight=42"
- "traefik.TCP.Services.Service1.LoadBalancer.Method=foobar"
- "traefik.TCP.Services.Service1.LoadBalancer.server.Port=42"
- "traefik.TCP.Services.Service1.LoadBalancer.server.Weight=42"

View file

@ -14,14 +14,11 @@ The `Services` are responsible for configuring how to reach the actual services
```toml
[http.services]
[http.services.my-service.LoadBalancer]
method = "wrr" # Load Balancing based on weights
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-1/"
weight = 30 # 30% of the requests will go to that instance
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-2/"
weight = 70 # 70% of the requests will go to that instance
```
??? example "Declaring a TCP Service with Two Servers -- Using the [File Provider](../../providers/file.md)"
@ -52,21 +49,17 @@ The load balancers are able to load balance the requests between multiple instan
```toml
[http.services]
[http.services.my-service.LoadBalancer]
method = "wrr" # Load Balancing based on weights
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-1/"
weight = 50 # 50% of the requests will go to that instance
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-2/"
weight = 50 # 50% of the requests will go to that instance
```
#### Servers
Servers declare a single instance of your program.
The `url` option point to a specific instance.
The `weight` option defines the weight of the server for the load balancing algorithm.
!!! note
Paths in the servers' `url` have no effet.
@ -80,28 +73,21 @@ The `weight` option defines the weight of the server for the load balancing algo
[http.services.my-service.LoadBalancer]
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-1/"
weight = 1
```
#### Load-balancing
Various methods of load balancing are supported:
For now, only round robin load balancing is supported:
- `wrr`: Weighted Round Robin.
- `drr`: Dynamic Round Robin: increases weights on servers that perform better than others (rolls back to original weights when the server list is updated)
??? example "Load Balancing Using DRR -- Using the [File Provider](../../providers/file.md)"
??? example "Load Balancing -- Using the [File Provider](../../providers/file.md)"
```toml
[http.services]
[http.services.my-service.LoadBalancer]
method = "drr"
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-1/"
weight = 1
[[http.services.my-service.LoadBalancer.servers]]
url = "http://private-ip-server-1/"
weight = 1
```
#### Sticky sessions
@ -239,7 +225,3 @@ The `address` option (IP:Port) point to a specific instance.
[[tcp.services.my-service.LoadBalancer.servers]]
address = "xx.xx.xx.xx:xx"
```
!!! note "Weight"
The TCP LoadBalancer is currently a round robin only implementation and doesn't yet support weights.

View file

@ -46,7 +46,6 @@ level = "DEBUG"
[http.services.test.loadbalancer]
[[http.services.test.loadbalancer.servers]]
url = "http://127.0.0.1:9010"
weight = 1
[http.routers]
[http.routers.test]

View file

@ -46,7 +46,6 @@ level = "DEBUG"
[http.services.test.loadbalancer]
[[http.services.test.loadbalancer.servers]]
url = "http://127.0.0.1:9010"
weight = 1
[http.routers]
[http.routers.test]

View file

@ -2,7 +2,6 @@
[http.services.test.loadbalancer]
[[http.services.test.loadbalancer.servers]]
url = "http://127.0.0.1:9010"
weight = 1
[http.routers]
[http.routers.test]

View file

@ -29,9 +29,7 @@ level = "DEBUG"
passHostHeader = true
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:8989474"
weight = 1
[http.services.error.loadbalancer]
[[http.services.error.loadbalancer.servers]]
url = "http://{{.Server2}}:80"
weight = 1

View file

@ -29,9 +29,7 @@ level = "DEBUG"
passHostHeader = true
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:80"
weight = 1
[http.services.error.loadbalancer]
[[http.services.error.loadbalancer.servers]]
url = "http://{{.Server2}}:80"
weight = 1

View file

@ -7,4 +7,3 @@
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "http://172.17.0.2:80"
weight = 1

View file

@ -7,4 +7,3 @@
[http.services.service2.loadbalancer]
[[http.services.service2.loadbalancer.servers]]
url = "http://172.17.0.123:80"
weight = 1

View file

@ -25,4 +25,3 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
URL = "{{.Server}}"
weight = 10

View file

@ -30,17 +30,12 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "http://172.17.0.2:80"
weight = 10
[[http.services.service1.loadbalancer.servers]]
url = "http://172.17.0.3:80"
weight = 1
[http.services.service2]
[http.services.service2.loadbalancer]
method = "drr"
[[http.services.service2.loadbalancer.servers]]
url = "http://172.17.0.4:80"
weight = 1
[[http.services.service2.loadbalancer.servers]]
url = "http://172.17.0.5:80"
weight = 2

View file

@ -27,7 +27,6 @@ rootCAs = [ """{{ .CertContent }}""" ]
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "https://127.0.0.1:{{ .GRPCServerPort }}"
weight = 1
[tlsStores.default.DefaultCertificate]
certFile = """{{ .CertContent }}"""

View file

@ -23,4 +23,3 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "h2c://127.0.0.1:{{ .GRPCServerPort }}"
weight = 1

View file

@ -25,7 +25,6 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "h2c://127.0.0.1:{{ .GRPCServerPort }}"
weight = 1
[tlsStores.default.DefaultCertificate]
certFile = """{{ .CertContent }}"""

View file

@ -27,7 +27,6 @@ insecureSkipVerify = true
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "https://127.0.0.1:{{ .GRPCServerPort }}"
weight = 1
[tlsStores.default.DefaultCertificate]
certFile = """{{ .CertContent }}"""

View file

@ -34,7 +34,6 @@ rootCAs = [ """{{ .CertContent }}""" ]
flushInterval="1ms"
[[http.services.service1.loadbalancer.servers]]
url = "https://127.0.0.1:{{ .GRPCServerPort }}"
weight = 1
[tlsStores.default.DefaultCertificate]
certFile = """{{ .CertContent }}"""

View file

@ -21,4 +21,3 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "http://172.17.0.2:80"
weight = 1

View file

@ -28,4 +28,3 @@ level = "DEBUG"
[http.services.service1.loadbalancer]
[[http.services.service1.loadbalancer.servers]]
url = "http://172.17.0.2:80"
weight = 1

View file

@ -1,36 +0,0 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.http1]
address = ":8000"
[entryPoints.http2]
address = ":9000"
[api]
[providers]
[providers.file]
[http.routers]
[http.routers.router1]
service = "service1"
Rule = "Host(`test.localhost`)"
[http.services]
[http.services.service1.loadbalancer]
method = "wrr"
[http.services.service1.loadbalancer.healthcheck]
path = "/health"
interval = "1s"
timeout = "0.9s"
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:80"
weight = 1
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server2}}:80"
weight = 1

View file

@ -23,14 +23,11 @@ level = "DEBUG"
[http.services]
[http.services.service1.loadbalancer]
method = "drr"
[http.services.service1.loadbalancer.healthcheck]
path = "/health"
interval = "1s"
timeout = "0.9s"
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:80"
weight = 1
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server2}}:80"
weight = 1

View file

@ -21,7 +21,6 @@ level = "DEBUG"
[http.services]
[http.services.service1.loadbalancer]
method = "drr"
[http.services.service1.loadbalancer.healthcheck]
path = "/health"
port = 80
@ -29,4 +28,3 @@ level = "DEBUG"
timeout = "0.9s"
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:81"
weight = 1

View file

@ -27,7 +27,5 @@ level = "DEBUG"
timeout = "0.9s"
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server1}}:80"
weight = 1
[[http.services.service1.loadbalancer.servers]]
url = "http://{{.Server2}}:80"
weight = 1

View file

@ -30,13 +30,11 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9010"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9020"
Weight = 1
[[tls]]
[tls.certificate]

View file

@ -30,13 +30,11 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9010"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9020"
Weight = 1
[[tls]]
[tls.certificate]

View file

@ -29,13 +29,11 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9010"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9020"
Weight = 1
[[tls]]
[tls.certificate]

View file

@ -14,13 +14,11 @@
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:9010"
weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
url = "http://127.0.0.1:9020"
weight = 1
[[tls]]
# bad certificates to validate the loop on the certificate appending

View file

@ -30,7 +30,6 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:9010"
weight = 1
[[tls]]
[tls.certificate]

View file

@ -170,4 +170,3 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:80"
weight = 1

View file

@ -30,13 +30,11 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9010"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://127.0.0.1:9020"
Weight = 1
[[tls]]
[tls.certificate]

View file

@ -30,7 +30,6 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:9010"
weight = 1
[[tls]]
[tls.certificate]

View file

@ -30,7 +30,6 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:9010"
weight = 1
[[tls]]
[tls.certificate]

View file

@ -25,7 +25,6 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
url = "http://127.0.0.1:9010"
weight = 1
[tlsOptions.default]
sniStrict = true

View file

@ -44,4 +44,3 @@ fblo6RBxUQ==
[[http.services.service1.LoadBalancer.Servers]]
URL = "{{ .BackendHost }}"
Weight = 1

View file

@ -29,4 +29,3 @@ rootCAs = [ "fixtures/https/rootcas/local.crt"]
[[http.services.service1.LoadBalancer.Servers]]
URL = "{{ .BackendHost }}"
Weight = 1

View file

@ -35,4 +35,3 @@ entryPoint = "api"
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://127.0.0.1:8081"
Weight = 1

View file

@ -30,4 +30,3 @@ level = "DEBUG"
[[http.services.service-test.LoadBalancer.Servers]]
URL = "http://{{ .IP }}"
Weight = 1

View file

@ -22,7 +22,6 @@ level = "DEBUG"
[[http.services.service.LoadBalancer.Servers]]
URL = "{{.Server}}"
Weight = 1
[http.middlewares]
[http.middlewares.customheader.Headers.CustomRequestHeaders]
X-Custom="CustomValue"

View file

@ -27,4 +27,3 @@ level = "DEBUG"
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.WhoamiIP}}"
Weight = 1

View file

@ -27,4 +27,3 @@ level = "DEBUG"
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.WhoamiIP}}"
Weight = 1

View file

@ -36,4 +36,3 @@ level = "DEBUG"
passHostHeader = true
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.Server1}}:80"
Weight = 1

View file

@ -32,5 +32,4 @@ level = "DEBUG"
[[http.services.service.LoadBalancer.Servers]]
URL = "{{.Server}}"
Weight = 1

View file

@ -29,8 +29,6 @@ level = "DEBUG"
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.WhoamiEndpoint}}:8080"
Weight = 1
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.WhoamiEndpoint}}:80"
Weight = 1

View file

@ -30,10 +30,8 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "{{ .Server1 }}"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "{{ .Server2 }}"
Weight = 1

View file

@ -30,7 +30,6 @@ level = "DEBUG"
[http.services.whoami.loadbalancer]
[[http.services.whoami.loadbalancer.servers]]
url = "http://localhost:8085"
weight=1
[tcp]
[tcp.routers]
[tcp.routers.to-whoami-a]
@ -53,26 +52,17 @@ level = "DEBUG"
entryPoints = [ "tcp" ]
[tcp.routers.to-whoami-no-cert.tls]
[tcp.services.whoami-a]
[tcp.services.whoami-a.loadbalancer]
method = "wrr"
[[tcp.services.whoami-a.loadbalancer.servers]]
address = "localhost:8081"
weight = 1
[tcp.services.whoami-b]
[tcp.services.whoami-b.loadbalancer]
method = "wrr"
[[tcp.services.whoami-b.loadbalancer.servers]]
address = "localhost:8082"
weight = 1
[tcp.services.whoami-no-cert]
[tcp.services.whoami-no-cert.loadbalancer]
method = "wrr"
[[tcp.services.whoami-no-cert.loadbalancer.servers]]
address = "localhost:8083"
weight = 1
[[tls]]
[tls.certificate]

View file

@ -45,23 +45,14 @@ level = "DEBUG"
[[tcp.services.whoami-no-tls.loadbalancer.servers]]
address = "localhost:8084"
[tcp.services.whoami-a]
[tcp.services.whoami-a.loadbalancer]
method = "wrr"
[[tcp.services.whoami-a.loadbalancer.servers]]
address = "localhost:8081"
weight = 1
[tcp.services.whoami-b]
[tcp.services.whoami-b.loadbalancer]
method = "wrr"
[[tcp.services.whoami-b.loadbalancer.servers]]
address = "localhost:8082"
weight = 1
[tcp.services.whoami-no-cert]
[tcp.services.whoami-no-cert.loadbalancer]
method = "wrr"
[[tcp.services.whoami-no-cert.loadbalancer.servers]]
address = "localhost:8083"
weight = 1

View file

@ -35,10 +35,8 @@ level = "DEBUG"
[http.services.service1.LoadBalancer]
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://50.255.255.1"
Weight = 1
[http.services.service2]
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://{{.TimeoutEndpoint}}:9000"
Weight = 1

View file

@ -61,18 +61,15 @@ level = "DEBUG"
passHostHeader = true
[[http.services.service1.LoadBalancer.Servers]]
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
Weight = 1
[http.services.service2]
passHostHeader = true
[http.services.service2.LoadBalancer]
[[http.services.service2.LoadBalancer.Servers]]
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
Weight = 1
[http.services.service3]
passHostHeader = true
[http.services.service3.LoadBalancer]
[[http.services.service3.LoadBalancer.Servers]]
URL = "http://{{.WhoAmiIP}}:{{.WhoAmiPort}}"
Weight = 1

View file

@ -25,4 +25,3 @@ level = "DEBUG"
passHostHeader = true
[[http.services.service1.LoadBalancer.Servers]]
URL = "{{ .WebsocketServer }}"
Weight = 1

View file

@ -29,7 +29,6 @@ insecureSkipVerify=true
PassHostHeader = true
[[http.services.service1.LoadBalancer.Servers]]
URL = "{{ .WebsocketServer }}"
Weight = 1
[tlsStores.default.DefaultCertificate]
certFile = "resources/tls/local.cert"

View file

@ -95,16 +95,8 @@ func (s *HealthCheckSuite) TestSimpleConfiguration(c *check.C) {
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
}
func (s *HealthCheckSuite) TestMultipleEntrypointsWrr(c *check.C) {
s.doTestMultipleEntrypoints(c, "fixtures/healthcheck/multiple-entrypoints-wrr.toml")
}
func (s *HealthCheckSuite) TestMultipleEntrypointsDrr(c *check.C) {
s.doTestMultipleEntrypoints(c, "fixtures/healthcheck/multiple-entrypoints-drr.toml")
}
func (s *HealthCheckSuite) doTestMultipleEntrypoints(c *check.C, fixture string) {
file := s.adaptFile(c, fixture, struct {
func (s *HealthCheckSuite) TestMultipleEntrypoints(c *check.C) {
file := s.adaptFile(c, "fixtures/healthcheck/multiple-entrypoints.toml", struct {
Server1 string
Server2 string
}{s.whoami1IP, s.whoami2IP})

View file

@ -20,7 +20,6 @@ server2:
- traefik.http.routers.rt-server2.entryPoints=web
- traefik.http.routers.rt-server2.rule=Host("frontend2.docker.local")
- traefik.http.services.service2.loadbalancer.server.port=80
- traefik.http.services.service2.loadbalancer.method=drr
server3:
image: containous/whoami
labels:
@ -28,7 +27,6 @@ server3:
- traefik.http.routers.rt-server3.entryPoints=web
- traefik.http.routers.rt-server3.rule=Host("frontend2.docker.local")
- traefik.http.services.service2.loadbalancer.server.port=80
- traefik.http.services.service2.loadbalancer.method=drr
authFrontend:
image: containous/whoami
labels:

View file

@ -47,7 +47,6 @@ func (s *RestSuite) TestSimpleConfiguration(c *check.C) {
Servers: []config.Server{
{
URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80",
Weight: 1,
},
},
},

View file

@ -40,10 +40,8 @@ func TestHandler_Configuration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -96,10 +94,8 @@ func TestHandler_Configuration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},

View file

@ -57,11 +57,9 @@
"loadbalancer": {
"servers": [
{
"url": "http://127.0.0.1",
"weight": 1
"url": "http://127.0.0.1"
}
],
"method": "wrr",
"passHostHeader": false
},
"usedBy": [
@ -91,11 +89,9 @@
"loadbalancer": {
"servers": [
{
"address": "127.0.0.1",
"weight": 1
"address": "127.0.0.1"
}
],
"method": "wrr"
]
},
"usedBy": [
"myprovider.tcpbar",

View file

@ -41,7 +41,6 @@ type RouterTCPTLSConfig struct {
type LoadBalancerService struct {
Stickiness *Stickiness `json:"stickiness,omitempty" toml:",omitempty" label:"allowEmpty"`
Servers []Server `json:"servers,omitempty" toml:",omitempty" label-slice-as-struct:"server"`
Method string `json:"method,omitempty" toml:",omitempty"`
HealthCheck *HealthCheck `json:"healthCheck,omitempty" toml:",omitempty"`
PassHostHeader bool `json:"passHostHeader" toml:",omitempty"`
ResponseForwarding *ResponseForwarding `json:"forwardingResponse,omitempty" toml:",omitempty"`
@ -50,7 +49,6 @@ type LoadBalancerService struct {
// TCPLoadBalancerService holds the LoadBalancerService configuration.
type TCPLoadBalancerService struct {
Servers []TCPServer `json:"servers,omitempty" toml:",omitempty" label-slice-as-struct:"server"`
Method string `json:"method,omitempty" toml:",omitempty"`
}
// Mergeable tells if the given service is mergeable.
@ -87,15 +85,9 @@ func (l *LoadBalancerService) Mergeable(loadBalancer *LoadBalancerService) bool
return reflect.DeepEqual(l, loadBalancer)
}
// SetDefaults Default values for a TCPLoadBalancerService.
func (l *TCPLoadBalancerService) SetDefaults() {
l.Method = "wrr"
}
// SetDefaults Default values for a LoadBalancerService.
func (l *LoadBalancerService) SetDefaults() {
l.PassHostHeader = true
l.Method = "wrr"
}
// ResponseForwarding holds configuration for the forward of the response.
@ -113,24 +105,16 @@ type Server struct {
URL string `json:"url" label:"-"`
Scheme string `toml:"-" json:"-"`
Port string `toml:"-" json:"-"`
Weight int `json:"weight"`
}
// TCPServer holds a TCP Server configuration
type TCPServer struct {
Address string `json:"address" label:"-"`
Port string `toml:"-" json:"-"`
Weight int `json:"weight"`
}
// SetDefaults Default values for a Server.
func (s *TCPServer) SetDefaults() {
s.Weight = 1
}
// SetDefaults Default values for a Server.
func (s *Server) SetDefaults() {
s.Weight = 1
s.Scheme = "http"
}

View file

@ -44,16 +44,9 @@ func TestPopulateUsedby(t *testing.T) {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8085",
Weight: 1,
{URL: "http://127.0.0.1:8085"},
{URL: "http://127.0.0.1:8086"},
},
{
URL: "http://127.0.0.1:8086",
Weight: 1,
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -83,13 +76,9 @@ func TestPopulateUsedby(t *testing.T) {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
{URL: "http://127.0.0.1"},
},
},
Method: "wrr",
},
},
},
},
@ -163,14 +152,11 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:8085",
Weight: 1,
},
{
URL: "http://127.0.0.1:8086",
Weight: 1,
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -184,14 +170,11 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:8087",
Weight: 1,
},
{
URL: "http://127.0.0.1:8088",
Weight: 1,
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -242,10 +225,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -315,10 +296,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -361,10 +340,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -415,10 +392,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -517,15 +492,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8085",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8086",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -553,10 +525,8 @@ func TestPopulateUsedby(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -632,15 +602,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8085",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8086",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -651,15 +618,12 @@ func TestPopulateUsedby(t *testing.T) {
{
Address: "127.0.0.1",
Port: "8087",
Weight: 1,
},
{
Address: "127.0.0.1",
Port: "8088",
Weight: 1,
},
},
Method: "wrr",
},
},
},

View file

@ -284,7 +284,6 @@ func TestPrometheusMetricRemoval(t *testing.T) {
th.WithServiceName("bar")),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("wrr"),
th.WithServers(th.WithServer("http://localhost:9000"))),
),
),

View file

@ -78,7 +78,6 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container d
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
lb.SetDefaults()
configuration.Services[serviceName] = &config.TCPService{
LoadBalancer: lb,
}
@ -151,7 +150,6 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
if len(loadBalancer.Servers) == 0 {
server := config.TCPServer{}
server.SetDefaults()
loadBalancer.Servers = []config.TCPServer{server}
}

View file

@ -61,10 +61,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -112,10 +110,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -165,10 +161,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -211,10 +205,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -257,10 +249,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -308,10 +298,8 @@ func TestDefaultRule(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -393,10 +381,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -463,10 +449,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -475,10 +459,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -543,14 +525,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -565,7 +544,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -599,10 +578,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -617,7 +594,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
},
@ -653,10 +630,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -699,10 +674,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -724,7 +697,7 @@ func Test_buildConfiguration(t *testing.T) {
Name: "Test",
Labels: map[string]string{
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -758,10 +731,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -777,8 +748,8 @@ func Test_buildConfiguration(t *testing.T) {
Name: "Test",
Labels: map[string]string{
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service2.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.services.Service2.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -807,10 +778,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -819,10 +788,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -831,14 +798,14 @@ func Test_buildConfiguration(t *testing.T) {
},
},
{
desc: "two containers with same service name and different LB methods",
desc: "two containers with same service name and different passhostheader",
containers: []dockerData{
{
ID: "1",
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -857,7 +824,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "false",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -890,14 +857,14 @@ func Test_buildConfiguration(t *testing.T) {
},
},
{
desc: "three containers with same service name and different LB methods",
desc: "three containers with same service name and different passhostheader",
containers: []dockerData{
{
ID: "1",
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "false",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -916,7 +883,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -935,7 +902,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "foo",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -975,7 +942,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -994,7 +961,7 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -1028,14 +995,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -1083,10 +1047,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1170,14 +1132,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1246,14 +1205,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1341,18 +1297,14 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
{
URL: "http://127.0.0.3:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1416,14 +1368,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1506,18 +1455,14 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
{
URL: "http://127.0.0.3:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1586,14 +1531,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1655,10 +1597,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1667,10 +1607,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1719,10 +1657,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1772,10 +1708,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "h2c://127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1820,10 +1754,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1832,10 +1764,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -2061,10 +1991,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -2124,10 +2052,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -2173,10 +2099,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -2219,10 +2143,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -2273,10 +2195,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -2298,7 +2218,7 @@ func Test_buildConfiguration(t *testing.T) {
"traefik.tcp.routers.foo.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.routers.foo.tls": "true",
"traefik.tcp.services.foo.loadbalancer.server.port": "8080",
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -2320,7 +2240,7 @@ func Test_buildConfiguration(t *testing.T) {
"traefik.tcp.routers.foo.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.routers.foo.tls": "true",
"traefik.tcp.services.foo.loadbalancer.server.port": "8080",
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -2350,14 +2270,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
{
Address: "127.0.0.2:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -2376,14 +2293,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -2422,10 +2336,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},

View file

@ -191,7 +191,6 @@ func getTestCases() []ProvideTestCase {
[http.services.application-{{ $e }}]
[[http.services.application-{{ $e }}.servers]]
url="http://127.0.0.1"
weight = 1
{{ end }}
`,
},
@ -318,7 +317,6 @@ func createServicesConfiguration(n int) string {
[http.services.application-%[1]d.loadbalancer]
[[http.services.application-%[1]d.loadbalancer.servers]]
url = "http://172.17.0.%[1]d:80"
weight = 1
`, i)
}
return conf

View file

@ -188,7 +188,6 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
if service.Spec.Type == corev1.ServiceTypeExternalName {
servers = append(servers, config.Server{
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
Weight: 1,
})
} else {
endpoints, endpointsExists, endpointsErr := client.GetEndpoints(namespace, svc.Name)
@ -225,7 +224,6 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
for _, addr := range subset.Addresses {
servers = append(servers, config.Server{
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
Weight: 1,
})
}
}
@ -332,7 +330,6 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
LoadBalancer: &config.LoadBalancerService{
Servers: allServers,
// TODO: support other strategies.
Method: "wrr",
PassHostHeader: true,
},
}

View file

@ -51,14 +51,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -99,14 +96,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -141,14 +135,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -157,14 +148,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -193,22 +181,17 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
{
URL: "http://10.10.0.3:8080",
Weight: 1,
},
{
URL: "http://10.10.0.4:8080",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -295,14 +278,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -332,14 +312,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -368,14 +345,11 @@ func TestLoadIngressRoutes(t *testing.T) {
Servers: []config.Server{
{
URL: "https://10.10.0.5:443",
Weight: 1,
},
{
URL: "https://10.10.0.6:443",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},

View file

@ -33,7 +33,6 @@ type TLS struct {
type Service struct {
Name string `json:"name"`
Port int32 `json:"port"`
// TODO Weight int `json:"weight,omitempty"`
HealthCheck *HealthCheck `json:"healthCheck,omitempty"`
Strategy string `json:"strategy,omitempty"`
}

View file

@ -196,7 +196,6 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
if service.Spec.Type == corev1.ServiceTypeExternalName {
servers = append(servers, config.Server{
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
Weight: 1,
})
} else {
endpoints, endpointsExists, endpointsErr := client.GetEndpoints(namespace, backend.ServiceName)
@ -234,7 +233,6 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
for _, addr := range subset.Addresses {
servers = append(servers, config.Server{
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
Weight: 1,
})
}
}
@ -243,7 +241,6 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
return &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: servers,
Method: "wrr",
PassHostHeader: true,
},
}, nil

View file

@ -51,16 +51,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -88,16 +85,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -125,16 +119,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -158,16 +149,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -190,12 +178,10 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/example-com/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.11.0.1:80",
Weight: 1,
},
},
},
@ -223,16 +209,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -260,16 +243,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -297,16 +277,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -341,16 +318,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -389,32 +363,26 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
},
"testing/service2/8082": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.2:8080",
Weight: 1,
},
{
URL: "http://10.21.0.2:8080",
Weight: 1,
},
},
},
@ -461,16 +429,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"default-backend": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
},
},
},
@ -494,16 +459,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8089",
Weight: 1,
},
{
URL: "http://10.21.0.1:8089",
Weight: 1,
},
},
},
@ -527,16 +489,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8089",
Weight: 1,
},
{
URL: "http://10.21.0.1:8089",
Weight: 1,
},
},
},
@ -560,16 +519,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8089",
Weight: 1,
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
},
},
},
@ -597,32 +553,26 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8089",
Weight: 1,
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
},
},
},
},
"testing/service1/carotte": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8090",
Weight: 1,
},
{
URL: "http://10.10.0.2:8090",
Weight: 1,
},
},
},
@ -650,32 +600,26 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8089",
Weight: 1,
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
},
},
},
},
"toto/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.11.0.1:8089",
Weight: 1,
},
{
URL: "http://10.11.0.2:8089",
Weight: 1,
},
},
},
@ -721,12 +665,10 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/8080": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://traefik.wtf:8080",
Weight: 1,
},
},
},
@ -750,12 +692,10 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/example-com/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.11.0.1:80",
Weight: 1,
},
},
},
@ -787,16 +727,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/443": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "https://10.10.0.1:443",
Weight: 1,
},
{
URL: "https://10.21.0.1:443",
Weight: 1,
},
},
},
@ -820,16 +757,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/8443": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "https://10.10.0.1:8443",
Weight: 1,
},
{
URL: "https://10.21.0.1:8443",
Weight: 1,
},
},
},
@ -854,16 +788,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/8443": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "https://10.10.0.1:8443",
Weight: 1,
},
{
URL: "https://10.21.0.1:8443",
Weight: 1,
},
},
},
@ -888,16 +819,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"default-backend": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.30.0.1:8080",
Weight: 1,
},
{
URL: "http://10.41.0.1:8080",
Weight: 1,
},
},
},
@ -921,12 +849,10 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Services: map[string]*config.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
Method: "wrr",
PassHostHeader: true,
Servers: []config.Server{
{
URL: "http://10.10.0.1:8080",
Weight: 1,
},
},
},

View file

@ -138,12 +138,10 @@ func TestDecodeConfiguration(t *testing.T) {
"traefik.http.services.Service0.loadbalancer.healthcheck.port": "42",
"traefik.http.services.Service0.loadbalancer.healthcheck.scheme": "foobar",
"traefik.http.services.Service0.loadbalancer.healthcheck.timeout": "foobar",
"traefik.http.services.Service0.loadbalancer.method": "foobar",
"traefik.http.services.Service0.loadbalancer.passhostheader": "true",
"traefik.http.services.Service0.loadbalancer.responseforwarding.flushinterval": "foobar",
"traefik.http.services.Service0.loadbalancer.server.scheme": "foobar",
"traefik.http.services.Service0.loadbalancer.server.port": "8080",
"traefik.http.services.Service0.loadbalancer.server.weight": "42",
"traefik.http.services.Service0.loadbalancer.stickiness.cookiename": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name0": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.headers.name1": "foobar",
@ -153,7 +151,6 @@ func TestDecodeConfiguration(t *testing.T) {
"traefik.http.services.Service1.loadbalancer.healthcheck.port": "42",
"traefik.http.services.Service1.loadbalancer.healthcheck.scheme": "foobar",
"traefik.http.services.Service1.loadbalancer.healthcheck.timeout": "foobar",
"traefik.http.services.Service1.loadbalancer.method": "foobar",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.services.Service1.loadbalancer.responseforwarding.flushinterval": "foobar",
"traefik.http.services.Service1.loadbalancer.server.scheme": "foobar",
@ -168,12 +165,8 @@ func TestDecodeConfiguration(t *testing.T) {
"traefik.tcp.routers.Router1.entrypoints": "foobar, fiibar",
"traefik.tcp.routers.Router1.service": "foobar",
"traefik.tcp.routers.Router1.tls.passthrough": "false",
"traefik.tcp.services.Service0.loadbalancer.method": "foobar",
"traefik.tcp.services.Service0.loadbalancer.server.Port": "42",
"traefik.tcp.services.Service0.loadbalancer.server.Weight": "42",
"traefik.tcp.services.Service1.loadbalancer.method": "foobar",
"traefik.tcp.services.Service1.loadbalancer.server.Port": "42",
"traefik.tcp.services.Service1.loadbalancer.server.Weight": "42",
}
configuration, err := DecodeConfiguration(labels)
@ -211,10 +204,8 @@ func TestDecodeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
},
},
Method: "foobar",
},
},
"Service1": {
@ -222,10 +213,8 @@ func TestDecodeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
},
},
Method: "foobar",
},
},
},
@ -522,10 +511,8 @@ func TestDecodeConfiguration(t *testing.T) {
{
Scheme: "foobar",
Port: "8080",
Weight: 42,
},
},
Method: "foobar",
HealthCheck: &config.HealthCheck{
Scheme: "foobar",
Path: "foobar",
@ -550,10 +537,8 @@ func TestDecodeConfiguration(t *testing.T) {
{
Scheme: "foobar",
Port: "8080",
Weight: 1,
},
},
Method: "foobar",
HealthCheck: &config.HealthCheck{
Scheme: "foobar",
Path: "foobar",
@ -612,10 +597,8 @@ func TestEncodeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
},
},
Method: "foobar",
},
},
"Service1": {
@ -623,10 +606,8 @@ func TestEncodeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
},
},
Method: "foobar",
},
},
},
@ -922,10 +903,8 @@ func TestEncodeConfiguration(t *testing.T) {
{
Scheme: "foobar",
Port: "8080",
Weight: 42,
},
},
Method: "foobar",
HealthCheck: &config.HealthCheck{
Scheme: "foobar",
Path: "foobar",
@ -950,10 +929,8 @@ func TestEncodeConfiguration(t *testing.T) {
{
Scheme: "foobar",
Port: "8080",
Weight: 42,
},
},
Method: "foobar",
HealthCheck: &config.HealthCheck{
Scheme: "foobar",
Path: "foobar",
@ -1104,12 +1081,10 @@ func TestEncodeConfiguration(t *testing.T) {
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Port": "42",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Timeout": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.Method": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.PassHostHeader": "true",
"traefik.HTTP.Services.Service0.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.server.Port": "8080",
"traefik.HTTP.Services.Service0.LoadBalancer.server.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.server.Weight": "42",
"traefik.HTTP.Services.Service0.LoadBalancer.Stickiness.CookieName": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name0": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Headers.name1": "foobar",
@ -1119,13 +1094,11 @@ func TestEncodeConfiguration(t *testing.T) {
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Port": "42",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Scheme": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.HealthCheck.Timeout": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.Method": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.PassHostHeader": "true",
"traefik.HTTP.Services.Service1.LoadBalancer.ResponseForwarding.FlushInterval": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.server.Port": "8080",
"traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar",
"traefik.HTTP.Services.Service1.LoadBalancer.server.Weight": "42",
"traefik.TCP.Routers.Router0.Rule": "foobar",
"traefik.TCP.Routers.Router0.EntryPoints": "foobar, fiibar",
@ -1135,12 +1108,8 @@ func TestEncodeConfiguration(t *testing.T) {
"traefik.TCP.Routers.Router1.EntryPoints": "foobar, fiibar",
"traefik.TCP.Routers.Router1.Service": "foobar",
"traefik.TCP.Routers.Router1.TLS.Passthrough": "false",
"traefik.TCP.Services.Service0.LoadBalancer.Method": "foobar",
"traefik.TCP.Services.Service0.LoadBalancer.server.Port": "42",
"traefik.TCP.Services.Service0.LoadBalancer.server.Weight": "42",
"traefik.TCP.Services.Service1.LoadBalancer.Method": "foobar",
"traefik.TCP.Services.Service1.LoadBalancer.server.Port": "42",
"traefik.TCP.Services.Service1.LoadBalancer.server.Weight": "42",
}
for key, val := range expected {

View file

@ -131,7 +131,6 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, app maratho
if len(conf.Services) == 0 {
conf.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
lb.SetDefaults()
conf.Services[appName] = &config.TCPService{
LoadBalancer: lb,
}
@ -141,7 +140,6 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, app maratho
var servers []config.TCPServer
defaultServer := config.TCPServer{}
defaultServer.SetDefaults()
if len(service.LoadBalancer.Servers) > 0 {
defaultServer = service.LoadBalancer.Servers[0]
@ -212,7 +210,6 @@ func (p *Provider) getTCPServer(app marathon.Application, task marathon.Task, ex
server := config.TCPServer{
Address: net.JoinHostPort(host, port),
Weight: 1,
}
return server, nil
@ -231,7 +228,6 @@ func (p *Provider) getServer(app marathon.Application, task marathon.Task, extra
server := config.Server{
URL: fmt.Sprintf("%s://%s", defaultServer.Scheme, net.JoinHostPort(host, port)),
Weight: 1,
}
return server, nil

View file

@ -62,10 +62,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -118,10 +116,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -166,10 +162,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -212,14 +206,11 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
},
{
URL: "http://localhost:8081",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -264,22 +255,17 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
},
{
URL: "http://localhost:8081",
Weight: 1,
},
{
URL: "http://localhost:8082",
Weight: 1,
},
{
URL: "http://localhost:8083",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -320,20 +306,16 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
"bar": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8081",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -367,14 +349,11 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
{
URL: "http://localhost:81",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -389,7 +368,7 @@ func TestBuildConfiguration(t *testing.T) {
appID("/app"),
appPorts(80),
withTasks(localhostTask(taskPorts(80))),
withLabel("traefik.http.services.Service1.loadbalancer.method", "drr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -409,10 +388,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
}},
},
@ -426,7 +403,7 @@ func TestBuildConfiguration(t *testing.T) {
appID("/app"),
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.services.Service1.loadbalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"),
withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"),
withLabel("traefik.http.routers.Router1.service", "Service1"),
)),
@ -449,10 +426,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -482,10 +457,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -507,7 +480,7 @@ func TestBuildConfiguration(t *testing.T) {
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"),
withLabel("traefik.http.services.Service1.loadbalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -528,10 +501,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -547,8 +518,8 @@ func TestBuildConfiguration(t *testing.T) {
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"),
withLabel("traefik.http.services.Service1.loadbalancer.method", "wrr"),
withLabel("traefik.http.services.Service2.loadbalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"),
withLabel("traefik.http.services.Service2.loadbalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -564,10 +535,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -576,10 +545,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -588,19 +555,19 @@ func TestBuildConfiguration(t *testing.T) {
},
},
{
desc: "two apps with same service name and different LB methods",
desc: "two apps with same service name and different passhostheader",
applications: withApplications(
application(
appID("/app"),
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.services.Service1.loadbalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "false"),
),
application(
appID("/app2"),
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.services.Service1.loadbalancer.method", "drr"),
withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -668,10 +635,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -680,10 +645,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -729,10 +692,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -741,10 +702,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -781,10 +740,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -793,10 +750,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -812,14 +767,14 @@ func TestBuildConfiguration(t *testing.T) {
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"),
withLabel("traefik.http.services.Service1.LoadBalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.LoadBalancer.passhostheader", "true"),
),
application(
appID("/app2"),
appPorts(80, 81),
withTasks(localhostTask(taskPorts(80, 81))),
withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"),
withLabel("traefik.http.services.Service1.LoadBalancer.method", "wrr"),
withLabel("traefik.http.services.Service1.LoadBalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -840,14 +795,11 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -884,10 +836,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -896,10 +846,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -935,10 +883,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -975,10 +921,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "h2c://localhost:90",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1010,10 +954,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1022,10 +964,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1209,10 +1149,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1256,10 +1194,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1295,10 +1231,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1331,10 +1265,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "localhost:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -1364,10 +1296,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "localhost:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -1405,10 +1335,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "localhost:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -1430,7 +1358,7 @@ func TestBuildConfiguration(t *testing.T) {
withLabel("traefik.tcp.routers.foo.rule", "HostSNI(`foo.bar`)"),
withLabel("traefik.tcp.routers.foo.tls", "true"),
withLabel("traefik.tcp.services.foo.loadbalancer.server.port", "8080"),
withLabel("traefik.http.services.bar.loadbalancer.method", "drr"),
withLabel("traefik.http.services.bar.loadbalancer.passhostheader", "true"),
)),
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
@ -1447,10 +1375,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "localhost:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -1469,10 +1395,8 @@ func TestBuildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -1591,12 +1515,10 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://localhost:80",
Weight: 1,
},
},
},
@ -1611,7 +1533,6 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
error: "unable to process ports for /app taskID: no port found",
@ -1629,12 +1550,10 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "88",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://localhost:88",
Weight: 1,
},
},
},
@ -1650,7 +1569,6 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "aaaa",
Weight: 1,
},
expected: expected{
error: `unable to process ports for /app taskID: strconv.Atoi: parsing "aaaa": invalid syntax`,
@ -1668,7 +1586,6 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "-6",
Weight: 1,
},
expected: expected{
error: `unable to process ports for /app taskID: explicitly specified port -6 must be greater than zero`,
@ -1686,12 +1603,10 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "index:1",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://localhost:81",
Weight: 1,
},
},
},
@ -1707,7 +1622,6 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "index:2",
Weight: 1,
},
expected: expected{
error: "unable to process ports for /app taskID: index 2 must be within range (0, 1)",
@ -1725,7 +1639,6 @@ func TestGetServer(t *testing.T) {
defaultServer: config.Server{
Scheme: "http",
Port: "index:aaa",
Weight: 1,
},
expected: expected{
error: `unable to process ports for /app taskID: strconv.Atoi: parsing "aaa": invalid syntax`,
@ -1743,12 +1656,10 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://localhost:80",
Weight: 1,
},
},
},
@ -1764,12 +1675,10 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://127.0.0.1:88",
Weight: 1,
},
},
},
@ -1785,12 +1694,10 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
},
@ -1806,12 +1713,10 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://localhost:80",
Weight: 1,
},
},
},
@ -1837,12 +1742,10 @@ func TestGetServer(t *testing.T) {
},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
server: config.Server{
URL: "http://127.0.0.1:88",
Weight: 1,
},
},
},
@ -1867,7 +1770,6 @@ func TestGetServer(t *testing.T) {
},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
error: "found 2 task IP addresses but missing IP address index for Marathon application /app on task taskID",
@ -1894,7 +1796,6 @@ func TestGetServer(t *testing.T) {
},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
error: "cannot use IP address index to select from 2 task IP addresses for Marathon application /app on task taskID",
@ -1916,7 +1817,6 @@ func TestGetServer(t *testing.T) {
extraConf: configuration{},
defaultServer: config.Server{
Scheme: "http",
Weight: 1,
},
expected: expected{
error: "missing IP address for Marathon application /app on task taskID",

View file

@ -74,7 +74,6 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service ran
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
lb.SetDefaults()
configuration.Services[serviceName] = &config.TCPService{
LoadBalancer: lb,
}
@ -155,7 +154,6 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
if len(loadBalancer.Servers) == 0 {
server := config.TCPServer{}
server.SetDefaults()
loadBalancer.Servers = []config.TCPServer{server}
}
@ -173,7 +171,6 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
for _, containerIP := range service.Containers {
servers = append(servers, config.TCPServer{
Address: net.JoinHostPort(containerIP, port),
Weight: 1,
})
}
@ -208,7 +205,6 @@ func (p *Provider) addServers(ctx context.Context, service rancherData, loadBala
for _, containerIP := range service.Containers {
servers = append(servers, config.Server{
URL: fmt.Sprintf("%s://%s", loadBalancer.Servers[0].Scheme, net.JoinHostPort(containerIP, port)),
Weight: 1,
})
}

View file

@ -48,10 +48,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -102,10 +100,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -114,10 +110,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -168,14 +162,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -184,10 +175,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://128.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -201,7 +190,7 @@ func Test_buildConfiguration(t *testing.T) {
{
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
},
@ -230,10 +219,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -320,10 +307,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -404,10 +389,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -459,10 +442,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -503,10 +484,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -545,10 +524,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -583,10 +560,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -629,10 +604,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -653,7 +626,7 @@ func Test_buildConfiguration(t *testing.T) {
"traefik.tcp.routers.foo.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.routers.foo.tls": "true",
"traefik.tcp.services.foo.loadbalancer.server.port": "8080",
"traefik.http.services.Service1.loadbalancer.method": "drr",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
Port: "80/tcp",
Containers: []string{"127.0.0.1", "127.0.0.2"},
@ -676,14 +649,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
{
Address: "127.0.0.2:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -702,14 +672,11 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -740,10 +707,8 @@ func Test_buildConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:8080",
Weight: 1,
},
},
Method: "wrr",
},
},
},

View file

@ -51,10 +51,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -90,10 +88,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -115,10 +111,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -141,10 +135,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -184,10 +176,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -226,10 +216,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -251,10 +239,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -277,10 +263,8 @@ func TestRouterManager_Get(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -374,10 +358,8 @@ func TestAccessLog(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -404,10 +386,8 @@ func TestAccessLog(t *testing.T) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -471,14 +451,11 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1:8085",
Weight: 1,
},
{
URL: "http://127.0.0.1:8086",
Weight: 1,
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -508,10 +485,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -537,10 +512,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -566,10 +539,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -611,10 +582,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -653,10 +622,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -686,10 +653,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -787,10 +752,8 @@ func BenchmarkRouterServe(b *testing.B) {
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
},
},
Method: "wrr",
},
},
}
@ -833,10 +796,8 @@ func BenchmarkService(b *testing.B) {
Servers: []config.Server{
{
URL: "tchouck",
Weight: 1,
},
},
Method: "wrr",
},
},
}

View file

@ -32,7 +32,6 @@ func TestRuntimeConfiguration(t *testing.T) {
Port: "8086",
},
},
Method: "wrr",
},
},
},
@ -67,7 +66,6 @@ func TestRuntimeConfiguration(t *testing.T) {
Address: "127.0.0.1:80",
},
},
Method: "wrr",
},
},
},
@ -100,10 +98,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},
@ -135,10 +131,8 @@ func TestRuntimeConfiguration(t *testing.T) {
Servers: []config.TCPServer{
{
Address: "127.0.0.1:80",
Weight: 1,
},
},
Method: "wrr",
},
},
},

View file

@ -40,7 +40,6 @@ func TestReuseService(t *testing.T) {
th.WithBasicAuth(&config.BasicAuth{Users: []string{"foo:bar"}}),
)),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("wrr"),
th.WithServers(th.WithServer(testServer.URL))),
),
)

View file

@ -161,7 +161,6 @@ func TestServerResponseEmptyBackend(t *testing.T) {
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("wrr"),
th.WithServers(th.WithServer(testServerURL))),
),
)
@ -176,7 +175,21 @@ func TestServerResponseEmptyBackend(t *testing.T) {
expectedStatusCode: http.StatusNotFound,
},
{
desc: "Empty Backend LB-Drr",
desc: "Empty Backend LB",
config: func(testServerURL string) *config.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
th.WithServiceName("bar"),
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar")),
)
},
expectedStatusCode: http.StatusServiceUnavailable,
},
{
desc: "Empty Backend LB Sticky",
config: func(testServerURL string) *config.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
@ -185,14 +198,14 @@ func TestServerResponseEmptyBackend(t *testing.T) {
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("drr")),
th.WithStickiness("test")),
),
)
},
expectedStatusCode: http.StatusServiceUnavailable,
},
{
desc: "Empty Backend LB-Drr Sticky",
desc: "Empty Backend LB",
config: func(testServerURL string) *config.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
@ -200,15 +213,13 @@ func TestServerResponseEmptyBackend(t *testing.T) {
th.WithServiceName("bar"),
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("drr"), th.WithStickiness("test")),
),
th.WithLoadBalancerServices(th.WithService("bar")),
)
},
expectedStatusCode: http.StatusServiceUnavailable,
},
{
desc: "Empty Backend LB-Wrr",
desc: "Empty Backend LB Sticky",
config: func(testServerURL string) *config.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
@ -217,23 +228,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("wrr")),
),
)
},
expectedStatusCode: http.StatusServiceUnavailable,
},
{
desc: "Empty Backend LB-Wrr Sticky",
config: func(testServerURL string) *config.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
th.WithServiceName("bar"),
th.WithRule(routeRule)),
),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithLBMethod("wrr"), th.WithStickiness("test")),
th.WithStickiness("test")),
),
)
},

View file

@ -185,59 +185,21 @@ func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler
func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, service *config.LoadBalancerService, fwd http.Handler) (healthcheck.BalancerHandler, error) {
logger := log.FromContext(ctx)
logger.Debug("Creating load-balancer")
var options []roundrobin.LBOption
var stickySession *roundrobin.StickySession
var cookieName string
if stickiness := service.Stickiness; stickiness != nil {
cookieName = cookie.GetName(stickiness.CookieName, serviceName)
stickySession = roundrobin.NewStickySession(cookieName)
}
var lb healthcheck.BalancerHandler
if service.Method == "drr" {
logger.Debug("Creating drr load-balancer")
rr, err := roundrobin.New(fwd)
if err != nil {
return nil, err
}
if stickySession != nil {
options = append(options, roundrobin.EnableStickySession(roundrobin.NewStickySession(cookieName)))
logger.Debugf("Sticky session cookie name: %v", cookieName)
lb, err = roundrobin.NewRebalancer(rr, roundrobin.RebalancerStickySession(stickySession))
if err != nil {
return nil, err
}
} else {
lb, err = roundrobin.NewRebalancer(rr)
if err != nil {
return nil, err
}
}
} else {
if service.Method != "wrr" {
logger.Warnf("Invalid load-balancing method %q, fallback to 'wrr' method", service.Method)
}
logger.Debug("Creating wrr load-balancer")
if stickySession != nil {
logger.Debugf("Sticky session cookie name: %v", cookieName)
var err error
lb, err = roundrobin.New(fwd, roundrobin.EnableStickySession(stickySession))
lb, err := roundrobin.New(fwd, options...)
if err != nil {
return nil, err
}
} else {
var err error
lb, err = roundrobin.New(fwd)
if err != nil {
return nil, err
}
}
}
lbsu := healthcheck.NewLBStatusUpdater(lb, m.configs[serviceName])
if err := m.upsertServers(ctx, lbsu, service.Servers); err != nil {
@ -256,9 +218,9 @@ func (m *Manager) upsertServers(ctx context.Context, lb healthcheck.BalancerHand
return fmt.Errorf("error parsing server URL %s: %v", srv.URL, err)
}
logger.WithField(log.ServerName, name).Debugf("Creating server %d at %s with weight %d", name, u, srv.Weight)
logger.WithField(log.ServerName, name).Debugf("Creating server %d %s", name, u)
if err := lb.UpsertServer(u, roundrobin.Weight(srv.Weight)); err != nil {
if err := lb.UpsertServer(u, roundrobin.Weight(1)); err != nil {
return fmt.Errorf("error adding server %s to load balancer: %v", srv.URL, err)
}

View file

@ -36,7 +36,6 @@ func TestGetLoadBalancer(t *testing.T) {
Servers: []config.Server{
{
URL: ":",
Weight: 0,
},
},
},
@ -123,14 +122,11 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Servers: []config.Server{
{
URL: server1.URL,
Weight: 50,
},
{
URL: server2.URL,
Weight: 50,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -150,10 +146,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Servers: []config.Server{
{
URL: "http://foo",
Weight: 1,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -166,7 +160,6 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
serviceName: "test",
service: &config.LoadBalancerService{
Servers: []config.Server{},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -182,14 +175,11 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Servers: []config.Server{
{
URL: server1.URL,
Weight: 1,
},
{
URL: server2.URL,
Weight: 1,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -211,10 +201,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Servers: []config.Server{
{
URL: serverPassHost.URL,
Weight: 1,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -231,10 +219,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Servers: []config.Server{
{
URL: serverPassHostFalse.URL,
Weight: 1,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -284,7 +270,7 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*config.ServiceInfo{
"serviceName": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{Method: "wrr"},
LoadBalancer: &config.LoadBalancerService{},
},
},
},
@ -295,7 +281,7 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*config.ServiceInfo{
"provider-1.serviceName": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{Method: "wrr"},
LoadBalancer: &config.LoadBalancerService{},
},
},
},
@ -306,7 +292,7 @@ func TestManager_Build(t *testing.T) {
configs: map[string]*config.ServiceInfo{
"provider-1.serviceName": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{Method: "wrr"},
LoadBalancer: &config.LoadBalancerService{},
},
},
},

View file

@ -70,7 +70,7 @@ func TestManager_BuildTCP(t *testing.T) {
configs: map[string]*config.TCPServiceInfo{
"serviceName": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{Method: "wrr"},
LoadBalancer: &config.TCPLoadBalancerService{},
},
},
},
@ -81,7 +81,7 @@ func TestManager_BuildTCP(t *testing.T) {
configs: map[string]*config.TCPServiceInfo{
"provider-1.serviceName": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{Method: "wrr"},
LoadBalancer: &config.TCPLoadBalancerService{},
},
},
},
@ -92,7 +92,7 @@ func TestManager_BuildTCP(t *testing.T) {
configs: map[string]*config.TCPServiceInfo{
"provider-1.serviceName": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{Method: "wrr"},
LoadBalancer: &config.TCPLoadBalancerService{},
},
},
},
@ -110,7 +110,6 @@ func TestManager_BuildTCP(t *testing.T) {
Address: "foobar.com:80",
},
},
Method: "wrr",
},
},
},
@ -129,7 +128,6 @@ func TestManager_BuildTCP(t *testing.T) {
Address: "192.168.0.12:80",
},
},
Method: "wrr",
},
},
},
@ -148,7 +146,6 @@ func TestManager_BuildTCP(t *testing.T) {
Address: "foobar.com",
},
},
Method: "wrr",
},
},
},
@ -167,7 +164,6 @@ func TestManager_BuildTCP(t *testing.T) {
Address: "192.168.0.12",
},
},
Method: "wrr",
},
},
},

View file

@ -38,7 +38,6 @@ func (r *RRLoadBalancer) next() Handler {
r.lock.Lock()
defer r.lock.Unlock()
// FIXME handle weight
if r.current >= len(r.servers) {
r.current = 0
log.Debugf("Load balancer: going back to the first available server")

View file

@ -120,7 +120,7 @@ func WithRule(rule string) func(*config.Router) {
func WithServers(opts ...func(*config.Server)) func(*config.LoadBalancerService) {
return func(b *config.LoadBalancerService) {
for _, opt := range opts {
server := config.Server{Weight: 1}
server := config.Server{}
opt(&server)
b.Servers = append(b.Servers, server)
}
@ -137,13 +137,6 @@ func WithServer(url string, opts ...func(*config.Server)) func(*config.Server) {
}
}
// WithLBMethod is a helper to create a configuration.
func WithLBMethod(method string) func(*config.LoadBalancerService) {
return func(b *config.LoadBalancerService) {
b.Method = method
}
}
// WithStickiness is a helper to create a configuration.
func WithStickiness(cookieName string) func(*config.LoadBalancerService) {
return func(b *config.LoadBalancerService) {