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]]
[tcp.services.whoami-a.loadbalancer]
[[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]]
[tcp.services.whoami-b.loadbalancer]
[[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]]
[tcp.services.whoami-no-cert.loadbalancer]
[[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-a.loadbalancer]
[[tcp.services.whoami-a.loadbalancer.servers]]
address = "localhost:8081"
[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-b.loadbalancer]
[[tcp.services.whoami-b.loadbalancer.servers]]
address = "localhost:8082"
[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
[tcp.services.whoami-no-cert.loadbalancer]
[[tcp.services.whoami-no-cert.loadbalancer.servers]]
address = "localhost:8083"

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

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

View file

@ -39,11 +39,9 @@ func TestHandler_Configuration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.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:8086",
Weight: 1,
},
{URL: "http://127.0.0.1:8085"},
{URL: "http://127.0.0.1:8086"},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -83,12 +76,8 @@ 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",
},
},
},
@ -162,15 +151,12 @@ func TestPopulateUsedby(t *testing.T) {
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",
Weight: 1,
URL: "http://127.0.0.1:8086",
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -183,15 +169,12 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8087",
Weight: 1,
URL: "http://127.0.0.1:8087",
},
{
URL: "http://127.0.0.1:8088",
Weight: 1,
URL: "http://127.0.0.1:8088",
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -241,11 +224,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -314,11 +295,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -360,11 +339,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -414,11 +391,9 @@ func TestPopulateUsedby(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.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

@ -60,11 +60,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -111,11 +109,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -164,11 +160,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -210,11 +204,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -256,11 +248,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -307,11 +297,9 @@ func TestDefaultRule(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -392,11 +380,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -462,11 +448,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -474,11 +458,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -542,15 +524,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
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{
@ -598,11 +577,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -617,9 +594,9 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -652,11 +629,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -698,11 +673,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -723,8 +696,8 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -757,11 +730,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -776,9 +747,9 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
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.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.services.Service2.loadbalancer.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -806,11 +777,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -818,11 +787,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
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{
@ -1027,15 +994,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "drr",
PassHostHeader: true,
},
},
@ -1082,11 +1046,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1169,15 +1131,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1245,15 +1204,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1340,19 +1296,15 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
{
URL: "http://127.0.0.3:80",
Weight: 1,
URL: "http://127.0.0.3:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1415,15 +1367,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1505,19 +1454,15 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
{
URL: "http://127.0.0.3:80",
Weight: 1,
URL: "http://127.0.0.3:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1585,15 +1530,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1654,11 +1596,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1666,11 +1606,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1718,11 +1656,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1771,11 +1707,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "h2c://127.0.0.1:8080",
Weight: 1,
URL: "h2c://127.0.0.1:8080",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1819,11 +1753,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1831,11 +1763,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:8080",
Weight: 1,
URL: "http://127.0.0.1:8080",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -2060,11 +1990,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -2123,11 +2051,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
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",
},
},
},
@ -2295,10 +2215,10 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"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.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.passhostheader": "true",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
@ -2317,10 +2237,10 @@ func Test_buildConfiguration(t *testing.T) {
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"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.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.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",
},
},
},
@ -2375,15 +2292,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
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

@ -187,8 +187,7 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
var servers []config.Server
if service.Spec.Type == corev1.ServiceTypeExternalName {
servers = append(servers, config.Server{
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
Weight: 1,
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
})
} else {
endpoints, endpointsExists, endpointsErr := client.GetEndpoints(namespace, svc.Name)
@ -224,8 +223,7 @@ 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,
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
})
}
}
@ -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

@ -50,15 +50,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -98,15 +95,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -140,15 +134,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -156,15 +147,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -192,23 +180,18 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
{
URL: "http://10.10.0.3:8080",
Weight: 1,
URL: "http://10.10.0.3:8080",
},
{
URL: "http://10.10.0.4:8080",
Weight: 1,
URL: "http://10.10.0.4:8080",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -294,15 +277,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -331,15 +311,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://10.10.0.1:80",
Weight: 1,
URL: "http://10.10.0.1:80",
},
{
URL: "http://10.10.0.2:80",
Weight: 1,
URL: "http://10.10.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -367,15 +344,12 @@ func TestLoadIngressRoutes(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "https://10.10.0.5:443",
Weight: 1,
URL: "https://10.10.0.5:443",
},
{
URL: "https://10.10.0.6:443",
Weight: 1,
URL: "https://10.10.0.6:443",
},
},
Method: "wrr",
PassHostHeader: true,
},
},

View file

@ -31,9 +31,8 @@ type TLS struct {
// Service defines an upstream to proxy traffic.
type Service struct {
Name string `json:"name"`
Port int32 `json:"port"`
// TODO Weight int `json:"weight,omitempty"`
Name string `json:"name"`
Port int32 `json:"port"`
HealthCheck *HealthCheck `json:"healthCheck,omitempty"`
Strategy string `json:"strategy,omitempty"`
}

View file

@ -195,8 +195,7 @@ 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,
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
})
} else {
endpoints, endpointsExists, endpointsErr := client.GetEndpoints(namespace, backend.ServiceName)
@ -233,8 +232,7 @@ 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,
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
})
}
}
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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,
URL: "http://10.11.0.1:80",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
},
"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.10.0.2:8080",
},
{
URL: "http://10.21.0.2:8080",
Weight: 1,
URL: "http://10.21.0.2:8080",
},
},
},
@ -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.10.0.1:8080",
},
{
URL: "http://10.21.0.1:8080",
Weight: 1,
URL: "http://10.21.0.1:8080",
},
},
},
@ -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.10.0.1:8089",
},
{
URL: "http://10.21.0.1:8089",
Weight: 1,
URL: "http://10.21.0.1:8089",
},
},
},
@ -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.10.0.1:8089",
},
{
URL: "http://10.21.0.1:8089",
Weight: 1,
URL: "http://10.21.0.1:8089",
},
},
},
@ -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.1:8089",
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
URL: "http://10.10.0.2:8089",
},
},
},
@ -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.1:8089",
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
URL: "http://10.10.0.2:8089",
},
},
},
},
"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.1:8090",
},
{
URL: "http://10.10.0.2:8090",
Weight: 1,
URL: "http://10.10.0.2:8090",
},
},
},
@ -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.1:8089",
},
{
URL: "http://10.10.0.2:8089",
Weight: 1,
URL: "http://10.10.0.2:8089",
},
},
},
},
"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.1:8089",
},
{
URL: "http://10.11.0.2:8089",
Weight: 1,
URL: "http://10.11.0.2:8089",
},
},
},
@ -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,
URL: "http://traefik.wtf:8080",
},
},
},
@ -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,
URL: "http://10.11.0.1:80",
},
},
},
@ -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.10.0.1:443",
},
{
URL: "https://10.21.0.1:443",
Weight: 1,
URL: "https://10.21.0.1:443",
},
},
},
@ -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.10.0.1:8443",
},
{
URL: "https://10.21.0.1:8443",
Weight: 1,
URL: "https://10.21.0.1:8443",
},
},
},
@ -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.10.0.1:8443",
},
{
URL: "https://10.21.0.1:8443",
Weight: 1,
URL: "https://10.21.0.1:8443",
},
},
},
@ -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.30.0.1:8080",
},
{
URL: "http://10.41.0.1:8080",
Weight: 1,
URL: "http://10.41.0.1:8080",
},
},
},
@ -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,
URL: "http://10.10.0.1:8080",
},
},
},

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)
@ -210,22 +203,18 @@ func TestDecodeConfiguration(t *testing.T) {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
Port: "42",
},
},
Method: "foobar",
},
},
"Service1": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
Port: "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",
@ -611,22 +596,18 @@ func TestEncodeConfiguration(t *testing.T) {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
Port: "42",
},
},
Method: "foobar",
},
},
"Service1": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
{
Port: "42",
Weight: 42,
Port: "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,28 +1094,22 @@ 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",
"traefik.TCP.Routers.Router0.Service": "foobar",
"traefik.TCP.Routers.Router0.TLS.Passthrough": "false",
"traefik.TCP.Routers.Router1.Rule": "foobar",
"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",
"traefik.TCP.Routers.Router0.Rule": "foobar",
"traefik.TCP.Routers.Router0.EntryPoints": "foobar, fiibar",
"traefik.TCP.Routers.Router0.Service": "foobar",
"traefik.TCP.Routers.Router0.TLS.Passthrough": "false",
"traefik.TCP.Routers.Router1.Rule": "foobar",
"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.server.Port": "42",
"traefik.TCP.Services.Service1.LoadBalancer.server.Port": "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
@ -230,8 +227,7 @@ 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,
URL: fmt.Sprintf("%s://%s", defaultServer.Scheme, net.JoinHostPort(host, port)),
}
return server, nil

View file

@ -61,11 +61,9 @@ func TestBuildConfiguration(t *testing.T) {
"app": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -117,11 +115,9 @@ func TestBuildConfiguration(t *testing.T) {
"app": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -165,11 +161,9 @@ func TestBuildConfiguration(t *testing.T) {
"app": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -211,15 +205,12 @@ func TestBuildConfiguration(t *testing.T) {
"Service1": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
URL: "http://localhost:8080",
},
{
URL: "http://localhost:8081",
Weight: 1,
URL: "http://localhost:8081",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -263,23 +254,18 @@ func TestBuildConfiguration(t *testing.T) {
"Service1": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
URL: "http://localhost:8080",
},
{
URL: "http://localhost:8081",
Weight: 1,
URL: "http://localhost:8081",
},
{
URL: "http://localhost:8082",
Weight: 1,
URL: "http://localhost:8082",
},
{
URL: "http://localhost:8083",
Weight: 1,
URL: "http://localhost:8083",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -319,21 +305,17 @@ func TestBuildConfiguration(t *testing.T) {
"foo": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
URL: "http://localhost:8080",
},
},
Method: "wrr",
PassHostHeader: true,
}},
"bar": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8081",
Weight: 1,
URL: "http://localhost:8081",
},
},
Method: "wrr",
PassHostHeader: true,
}},
},
@ -366,15 +348,12 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
{
URL: "http://localhost:81",
Weight: 1,
URL: "http://localhost:81",
},
},
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{
@ -408,11 +387,9 @@ func TestBuildConfiguration(t *testing.T) {
"Service1": {LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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"),
)),
@ -448,11 +425,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -481,11 +456,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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{
@ -527,11 +500,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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{
@ -563,11 +534,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -575,11 +544,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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{
@ -667,11 +634,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -679,11 +644,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -728,11 +691,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -740,11 +701,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -780,11 +739,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -792,11 +749,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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{
@ -839,15 +794,12 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -883,11 +835,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -895,11 +845,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -934,11 +882,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -974,11 +920,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "h2c://localhost:90",
Weight: 1,
URL: "h2c://localhost:90",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1009,11 +953,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1021,11 +963,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:8080",
Weight: 1,
URL: "http://localhost:8080",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1208,11 +1148,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1255,11 +1193,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -1294,11 +1230,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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",
},
},
},
@ -1468,11 +1394,9 @@ func TestBuildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://localhost:80",
Weight: 1,
URL: "http://localhost:80",
},
},
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,
URL: "http://localhost:80",
},
},
},
@ -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,
URL: "http://localhost:88",
},
},
},
@ -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,
URL: "http://localhost:81",
},
},
},
@ -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,
URL: "http://localhost:80",
},
},
},
@ -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,
URL: "http://127.0.0.1:88",
},
},
},
@ -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,
URL: "http://127.0.0.1:80",
},
},
},
@ -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,
URL: "http://localhost:80",
},
},
},
@ -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,
URL: "http://127.0.0.1:88",
},
},
},
@ -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,
})
}
@ -207,8 +204,7 @@ func (p *Provider) addServers(ctx context.Context, service rancherData, loadBala
var servers []config.Server
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,
URL: fmt.Sprintf("%s://%s", loadBalancer.Servers[0].Scheme, net.JoinHostPort(containerIP, port)),
})
}

View file

@ -47,11 +47,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -101,11 +99,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -113,11 +109,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -167,15 +161,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -183,11 +174,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://128.0.0.1:80",
Weight: 1,
URL: "http://128.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -201,9 +190,9 @@ func Test_buildConfiguration(t *testing.T) {
{
Name: "Test",
Labels: map[string]string{
"traefik.http.services.Service1.loadbalancer.method": "wrr",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
"traefik.http.services.Service1.loadbalancer.passhostheader": "true",
"traefik.http.routers.Router1.rule": "Host(`foo.com`)",
"traefik.http.routers.Router1.service": "Service1",
},
Port: "80/tcp",
Containers: []string{"127.0.0.1"},
@ -229,11 +218,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -319,11 +306,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -403,11 +388,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -458,11 +441,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
Method: "wrr",
PassHostHeader: true,
},
},
@ -502,11 +483,9 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
},
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",
},
},
},
@ -650,10 +623,10 @@ func Test_buildConfiguration(t *testing.T) {
{
Name: "Test",
Labels: map[string]string{
"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.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.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",
},
},
},
@ -701,15 +671,12 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1:80",
Weight: 1,
URL: "http://127.0.0.1:80",
},
{
URL: "http://127.0.0.2:80",
Weight: 1,
URL: "http://127.0.0.2:80",
},
},
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

@ -50,11 +50,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -89,11 +87,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -114,11 +110,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -140,11 +134,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -183,11 +175,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -225,11 +215,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -250,11 +238,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -276,11 +262,9 @@ func TestRouterManager_Get(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -373,11 +357,9 @@ func TestAccessLog(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -403,11 +385,9 @@ func TestAccessLog(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
},
@ -470,15 +450,12 @@ func TestRuntimeConfiguration(t *testing.T) {
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",
Weight: 1,
URL: "http://127.0.0.1:8086",
},
},
Method: "wrr",
HealthCheck: &config.HealthCheck{
Interval: "500ms",
Path: "/health",
@ -507,11 +484,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -536,11 +511,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -565,11 +538,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -610,11 +581,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -652,11 +621,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -685,11 +652,9 @@ func TestRuntimeConfiguration(t *testing.T) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://127.0.0.1",
Weight: 1,
URL: "http://127.0.0.1",
},
},
Method: "wrr",
},
},
},
@ -786,11 +751,9 @@ func BenchmarkRouterServe(b *testing.B) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server.URL,
Weight: 1,
URL: server.URL,
},
},
Method: "wrr",
},
},
}
@ -832,11 +795,9 @@ func BenchmarkService(b *testing.B) {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "tchouck",
Weight: 1,
URL: "tchouck",
},
},
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,58 +185,20 @@ 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)
options = append(options, roundrobin.EnableStickySession(roundrobin.NewStickySession(cookieName)))
logger.Debugf("Sticky session cookie name: %v", 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 {
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))
if err != nil {
return nil, err
}
} else {
var err error
lb, err = roundrobin.New(fwd)
if err != nil {
return nil, err
}
}
lb, err := roundrobin.New(fwd, options...)
if err != nil {
return nil, err
}
lbsu := healthcheck.NewLBStatusUpdater(lb, m.configs[serviceName])
@ -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

@ -35,8 +35,7 @@ func TestGetLoadBalancer(t *testing.T) {
service: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: ":",
Weight: 0,
URL: ":",
},
},
},
@ -122,15 +121,12 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
service: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: server1.URL,
Weight: 50,
URL: server1.URL,
},
{
URL: server2.URL,
Weight: 50,
URL: server2.URL,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -149,11 +145,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
service: &config.LoadBalancerService{
Servers: []config.Server{
{
URL: "http://foo",
Weight: 1,
URL: "http://foo",
},
},
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{
{
@ -181,15 +174,12 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Stickiness: &config.Stickiness{},
Servers: []config.Server{
{
URL: server1.URL,
Weight: 1,
URL: server1.URL,
},
{
URL: server2.URL,
Weight: 1,
URL: server2.URL,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -210,11 +200,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
PassHostHeader: true,
Servers: []config.Server{
{
URL: serverPassHost.URL,
Weight: 1,
URL: serverPassHost.URL,
},
},
Method: "wrr",
},
expected: []ExpectedResult{
{
@ -230,11 +218,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
Stickiness: &config.Stickiness{},
Servers: []config.Server{
{
URL: serverPassHostFalse.URL,
Weight: 1,
URL: serverPassHostFalse.URL,
},
},
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) {