From 518a37e77673d84cf0e9e83067494bcfe25daf40 Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Wed, 5 Jun 2019 22:18:06 +0200 Subject: [PATCH] rework loadbalancer support --- docs/content/middlewares/chain.md | 1 - docs/content/middlewares/overview.md | 1 - docs/content/providers/docker.md | 2 +- docs/content/providers/file.md | 3 - docs/content/providers/marathon.md | 2 +- docs/content/providers/rancher.md | 4 +- .../reference/dynamic-configuration/file.toml | 6 - .../dynamic-configuration/labels.yml | 8 - docs/content/routing/services/index.md | 22 +- integration/fixtures/acme/acme_base.toml | 1 - integration/fixtures/acme/acme_tls.toml | 1 - integration/fixtures/acme/certificates.toml | 1 - integration/fixtures/error_pages/error.toml | 2 - integration/fixtures/error_pages/simple.toml | 2 - integration/fixtures/file/dir/simple1.toml | 1 - integration/fixtures/file/dir/simple2.toml | 1 - integration/fixtures/file/simple-hosts.toml | 1 - integration/fixtures/file/simple.toml | 7 +- integration/fixtures/grpc/config.toml | 1 - integration/fixtures/grpc/config_h2c.toml | 1 - .../fixtures/grpc/config_h2c_termination.toml | 1 - .../fixtures/grpc/config_insecure.toml | 1 - integration/fixtures/grpc/config_retry.toml | 1 - integration/fixtures/headers/basic.toml | 1 - integration/fixtures/headers/cors.toml | 1 - .../healthcheck/multiple-entrypoints-wrr.toml | 36 --- ...nts-drr.toml => multiple-entrypoints.toml} | 3 - .../fixtures/healthcheck/port_overload.toml | 2 - integration/fixtures/healthcheck/simple.toml | 2 - .../https/clientca/https_1ca1config.toml | 2 - .../https/clientca/https_2ca1config.toml | 2 - .../https/clientca/https_2ca2config.toml | 2 - integration/fixtures/https/dynamic_https.toml | 2 - .../https/dynamic_https_sni_default_cert.toml | 1 - .../fixtures/https/https_redirect.toml | 1 - integration/fixtures/https/https_sni.toml | 2 - .../https_sni_case_insensitive_dynamic.toml | 1 - .../https/https_sni_default_cert.toml | 1 - .../fixtures/https/https_sni_strict.toml | 1 - integration/fixtures/https/rootcas/https.toml | 1 - .../https/rootcas/https_with_file.toml | 1 - integration/fixtures/log_rotation_config.toml | 1 - integration/fixtures/multiple_provider.toml | 1 - integration/fixtures/multiprovider.toml | 1 - integration/fixtures/proxy-protocol/with.toml | 1 - .../fixtures/proxy-protocol/without.toml | 1 - integration/fixtures/ratelimit/simple.toml | 1 - integration/fixtures/reqacceptgrace.toml | 1 - integration/fixtures/retry/simple.toml | 2 - integration/fixtures/simple_stats.toml | 2 - integration/fixtures/tcp/mixed.toml | 22 +- .../fixtures/tcp/non-tls-fallback.toml | 27 +-- .../fixtures/timeout/forwarding_timeouts.toml | 2 - integration/fixtures/tracing/simple.toml | 3 - integration/fixtures/websocket/config.toml | 1 - .../fixtures/websocket/config_https.toml | 1 - integration/healthcheck_test.go | 12 +- integration/resources/compose/access_log.yml | 2 - integration/rest_test.go | 3 +- pkg/api/handler_test.go | 6 +- pkg/api/testdata/getrawdata.json | 10 +- pkg/config/dyn_config.go | 16 -- pkg/config/runtime_test.go | 58 +---- pkg/metrics/prometheus_test.go | 1 - pkg/provider/docker/config.go | 2 - pkg/provider/docker/config_test.go | 228 ++++++------------ pkg/provider/file/file_test.go | 2 - pkg/provider/kubernetes/crd/kubernetes.go | 7 +- .../kubernetes/crd/kubernetes_test.go | 62 ++--- .../crd/traefik/v1alpha1/ingressroute.go | 5 +- pkg/provider/kubernetes/ingress/kubernetes.go | 7 +- .../kubernetes/ingress/kubernetes_test.go | 170 ++++--------- pkg/provider/label/parser_test.go | 59 ++--- pkg/provider/marathon/config.go | 6 +- pkg/provider/marathon/config_test.go | 212 +++++----------- pkg/provider/rancher/config.go | 6 +- pkg/provider/rancher/config_test.go | 75 ++---- pkg/server/router/router_test.go | 79 ++---- pkg/server/router/tcp/router_test.go | 6 - pkg/server/server_configuration_test.go | 1 - pkg/server/server_test.go | 45 ++-- pkg/server/service/service.go | 58 +---- pkg/server/service/service_test.go | 36 +-- pkg/server/service/tcp/service_test.go | 10 +- pkg/tcp/rr_load_balancer.go | 1 - pkg/testhelpers/config.go | 9 +- 86 files changed, 339 insertions(+), 1055 deletions(-) delete mode 100644 integration/fixtures/healthcheck/multiple-entrypoints-wrr.toml rename integration/fixtures/healthcheck/{multiple-entrypoints-drr.toml => multiple-entrypoints.toml} (92%) diff --git a/docs/content/middlewares/chain.md b/docs/content/middlewares/chain.md index 1178976ef..e42eaac9b 100644 --- a/docs/content/middlewares/chain.md +++ b/docs/content/middlewares/chain.md @@ -134,5 +134,4 @@ labels: [http.services.service1.LoadBalancer] [[http.services.service1.LoadBalancer.Servers]] URL = "http://127.0.0.1:80" - Weight = 1 ``` diff --git a/docs/content/middlewares/overview.md b/docs/content/middlewares/overview.md index 03afef5df..30efa5b7d 100644 --- a/docs/content/middlewares/overview.md +++ b/docs/content/middlewares/overview.md @@ -92,7 +92,6 @@ labels: [[http.services.service1.LoadBalancer.Servers]] URL = "http://127.0.0.1:80" - Weight = 1 ``` ## Advanced Configuration diff --git a/docs/content/providers/docker.md b/docs/content/providers/docker.md index 54dd174d7..81fae7b66 100644 --- a/docs/content/providers/docker.md +++ b/docs/content/providers/docker.md @@ -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. diff --git a/docs/content/providers/file.md b/docs/content/providers/file.md index be90ddfb7..26284a074 100644 --- a/docs/content/providers/file.md +++ b/docs/content/providers/file.md @@ -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 diff --git a/docs/content/providers/marathon.md b/docs/content/providers/marathon.md index 52c5b549e..0b9b42274 100644 --- a/docs/content/providers/marathon.md +++ b/docs/content/providers/marathon.md @@ -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. diff --git a/docs/content/providers/rancher.md b/docs/content/providers/rancher.md index 3e69c62bb..a23f19e38 100644 --- a/docs/content/providers/rancher.md +++ b/docs/content/providers/rancher.md @@ -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. diff --git a/docs/content/reference/dynamic-configuration/file.toml b/docs/content/reference/dynamic-configuration/file.toml index a88ada9ee..016a3f867 100644 --- a/docs/content/reference/dynamic-configuration/file.toml +++ b/docs/content/reference/dynamic-configuration/file.toml @@ -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"] diff --git a/docs/content/reference/dynamic-configuration/labels.yml b/docs/content/reference/dynamic-configuration/labels.yml index 466839089..a2bbe146c 100644 --- a/docs/content/reference/dynamic-configuration/labels.yml +++ b/docs/content/reference/dynamic-configuration/labels.yml @@ -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" diff --git a/docs/content/routing/services/index.md b/docs/content/routing/services/index.md index cb4aca7dd..b75b4395b 100644 --- a/docs/content/routing/services/index.md +++ b/docs/content/routing/services/index.md @@ -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. \ No newline at end of file diff --git a/integration/fixtures/acme/acme_base.toml b/integration/fixtures/acme/acme_base.toml index 4f693fb6c..9d7deab1b 100644 --- a/integration/fixtures/acme/acme_base.toml +++ b/integration/fixtures/acme/acme_base.toml @@ -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] diff --git a/integration/fixtures/acme/acme_tls.toml b/integration/fixtures/acme/acme_tls.toml index eba84f38d..27280bd74 100644 --- a/integration/fixtures/acme/acme_tls.toml +++ b/integration/fixtures/acme/acme_tls.toml @@ -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] diff --git a/integration/fixtures/acme/certificates.toml b/integration/fixtures/acme/certificates.toml index 23efdd0ce..ff1653bfd 100644 --- a/integration/fixtures/acme/certificates.toml +++ b/integration/fixtures/acme/certificates.toml @@ -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] diff --git a/integration/fixtures/error_pages/error.toml b/integration/fixtures/error_pages/error.toml index 5d6d10932..c4d6d4c32 100644 --- a/integration/fixtures/error_pages/error.toml +++ b/integration/fixtures/error_pages/error.toml @@ -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 diff --git a/integration/fixtures/error_pages/simple.toml b/integration/fixtures/error_pages/simple.toml index 385def51b..f34230ff2 100644 --- a/integration/fixtures/error_pages/simple.toml +++ b/integration/fixtures/error_pages/simple.toml @@ -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 diff --git a/integration/fixtures/file/dir/simple1.toml b/integration/fixtures/file/dir/simple1.toml index 3e204d542..0fd29bce1 100644 --- a/integration/fixtures/file/dir/simple1.toml +++ b/integration/fixtures/file/dir/simple1.toml @@ -7,4 +7,3 @@ [http.services.service1.loadbalancer] [[http.services.service1.loadbalancer.servers]] url = "http://172.17.0.2:80" - weight = 1 diff --git a/integration/fixtures/file/dir/simple2.toml b/integration/fixtures/file/dir/simple2.toml index 52fec9cb1..b7c92dc0b 100644 --- a/integration/fixtures/file/dir/simple2.toml +++ b/integration/fixtures/file/dir/simple2.toml @@ -7,4 +7,3 @@ [http.services.service2.loadbalancer] [[http.services.service2.loadbalancer.servers]] url = "http://172.17.0.123:80" - weight = 1 diff --git a/integration/fixtures/file/simple-hosts.toml b/integration/fixtures/file/simple-hosts.toml index b8cd6b2b3..2aea9d96b 100644 --- a/integration/fixtures/file/simple-hosts.toml +++ b/integration/fixtures/file/simple-hosts.toml @@ -25,4 +25,3 @@ level = "DEBUG" [http.services.service1.loadbalancer] [[http.services.service1.loadbalancer.servers]] URL = "{{.Server}}" - weight = 10 diff --git a/integration/fixtures/file/simple.toml b/integration/fixtures/file/simple.toml index accd6032d..e152729a2 100644 --- a/integration/fixtures/file/simple.toml +++ b/integration/fixtures/file/simple.toml @@ -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 diff --git a/integration/fixtures/grpc/config.toml b/integration/fixtures/grpc/config.toml index c88ed6914..2aa10f1c9 100644 --- a/integration/fixtures/grpc/config.toml +++ b/integration/fixtures/grpc/config.toml @@ -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 }}""" diff --git a/integration/fixtures/grpc/config_h2c.toml b/integration/fixtures/grpc/config_h2c.toml index e1267ea22..b9d317e39 100644 --- a/integration/fixtures/grpc/config_h2c.toml +++ b/integration/fixtures/grpc/config_h2c.toml @@ -23,4 +23,3 @@ level = "DEBUG" [http.services.service1.loadbalancer] [[http.services.service1.loadbalancer.servers]] url = "h2c://127.0.0.1:{{ .GRPCServerPort }}" - weight = 1 diff --git a/integration/fixtures/grpc/config_h2c_termination.toml b/integration/fixtures/grpc/config_h2c_termination.toml index 2533bcc07..2042816b5 100644 --- a/integration/fixtures/grpc/config_h2c_termination.toml +++ b/integration/fixtures/grpc/config_h2c_termination.toml @@ -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 }}""" diff --git a/integration/fixtures/grpc/config_insecure.toml b/integration/fixtures/grpc/config_insecure.toml index 57e5a2499..406f4286a 100644 --- a/integration/fixtures/grpc/config_insecure.toml +++ b/integration/fixtures/grpc/config_insecure.toml @@ -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 }}""" diff --git a/integration/fixtures/grpc/config_retry.toml b/integration/fixtures/grpc/config_retry.toml index b873f724c..0073ca393 100644 --- a/integration/fixtures/grpc/config_retry.toml +++ b/integration/fixtures/grpc/config_retry.toml @@ -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 }}""" diff --git a/integration/fixtures/headers/basic.toml b/integration/fixtures/headers/basic.toml index a69314e18..750c5375b 100644 --- a/integration/fixtures/headers/basic.toml +++ b/integration/fixtures/headers/basic.toml @@ -21,4 +21,3 @@ level = "DEBUG" [http.services.service1.loadbalancer] [[http.services.service1.loadbalancer.servers]] url = "http://172.17.0.2:80" - weight = 1 diff --git a/integration/fixtures/headers/cors.toml b/integration/fixtures/headers/cors.toml index fde39cd63..91166e52c 100644 --- a/integration/fixtures/headers/cors.toml +++ b/integration/fixtures/headers/cors.toml @@ -28,4 +28,3 @@ level = "DEBUG" [http.services.service1.loadbalancer] [[http.services.service1.loadbalancer.servers]] url = "http://172.17.0.2:80" - weight = 1 diff --git a/integration/fixtures/healthcheck/multiple-entrypoints-wrr.toml b/integration/fixtures/healthcheck/multiple-entrypoints-wrr.toml deleted file mode 100644 index ca2e261f6..000000000 --- a/integration/fixtures/healthcheck/multiple-entrypoints-wrr.toml +++ /dev/null @@ -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 diff --git a/integration/fixtures/healthcheck/multiple-entrypoints-drr.toml b/integration/fixtures/healthcheck/multiple-entrypoints.toml similarity index 92% rename from integration/fixtures/healthcheck/multiple-entrypoints-drr.toml rename to integration/fixtures/healthcheck/multiple-entrypoints.toml index eb8fb1e22..42b11861c 100644 --- a/integration/fixtures/healthcheck/multiple-entrypoints-drr.toml +++ b/integration/fixtures/healthcheck/multiple-entrypoints.toml @@ -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 diff --git a/integration/fixtures/healthcheck/port_overload.toml b/integration/fixtures/healthcheck/port_overload.toml index 138ef9462..8b17a4724 100644 --- a/integration/fixtures/healthcheck/port_overload.toml +++ b/integration/fixtures/healthcheck/port_overload.toml @@ -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 diff --git a/integration/fixtures/healthcheck/simple.toml b/integration/fixtures/healthcheck/simple.toml index 5bb413241..0e0cea877 100644 --- a/integration/fixtures/healthcheck/simple.toml +++ b/integration/fixtures/healthcheck/simple.toml @@ -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 diff --git a/integration/fixtures/https/clientca/https_1ca1config.toml b/integration/fixtures/https/clientca/https_1ca1config.toml index 50755445c..3ee74c690 100644 --- a/integration/fixtures/https/clientca/https_1ca1config.toml +++ b/integration/fixtures/https/clientca/https_1ca1config.toml @@ -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] diff --git a/integration/fixtures/https/clientca/https_2ca1config.toml b/integration/fixtures/https/clientca/https_2ca1config.toml index 1443bb5ad..5497da6cd 100644 --- a/integration/fixtures/https/clientca/https_2ca1config.toml +++ b/integration/fixtures/https/clientca/https_2ca1config.toml @@ -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] diff --git a/integration/fixtures/https/clientca/https_2ca2config.toml b/integration/fixtures/https/clientca/https_2ca2config.toml index 6af488d6c..2b518170d 100644 --- a/integration/fixtures/https/clientca/https_2ca2config.toml +++ b/integration/fixtures/https/clientca/https_2ca2config.toml @@ -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] diff --git a/integration/fixtures/https/dynamic_https.toml b/integration/fixtures/https/dynamic_https.toml index 2c83ffa9d..949b3c4ed 100644 --- a/integration/fixtures/https/dynamic_https.toml +++ b/integration/fixtures/https/dynamic_https.toml @@ -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 diff --git a/integration/fixtures/https/dynamic_https_sni_default_cert.toml b/integration/fixtures/https/dynamic_https_sni_default_cert.toml index e8f4fd768..cb0bd446a 100644 --- a/integration/fixtures/https/dynamic_https_sni_default_cert.toml +++ b/integration/fixtures/https/dynamic_https_sni_default_cert.toml @@ -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] diff --git a/integration/fixtures/https/https_redirect.toml b/integration/fixtures/https/https_redirect.toml index 22e184dfa..b072200b1 100644 --- a/integration/fixtures/https/https_redirect.toml +++ b/integration/fixtures/https/https_redirect.toml @@ -170,4 +170,3 @@ level = "DEBUG" [http.services.service1.LoadBalancer] [[http.services.service1.LoadBalancer.Servers]] url = "http://127.0.0.1:80" - weight = 1 diff --git a/integration/fixtures/https/https_sni.toml b/integration/fixtures/https/https_sni.toml index 5be5d5154..944f11e24 100644 --- a/integration/fixtures/https/https_sni.toml +++ b/integration/fixtures/https/https_sni.toml @@ -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] diff --git a/integration/fixtures/https/https_sni_case_insensitive_dynamic.toml b/integration/fixtures/https/https_sni_case_insensitive_dynamic.toml index 059ba3086..d6501c9cc 100644 --- a/integration/fixtures/https/https_sni_case_insensitive_dynamic.toml +++ b/integration/fixtures/https/https_sni_case_insensitive_dynamic.toml @@ -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] diff --git a/integration/fixtures/https/https_sni_default_cert.toml b/integration/fixtures/https/https_sni_default_cert.toml index 0bf10dfcc..b5034dcea 100644 --- a/integration/fixtures/https/https_sni_default_cert.toml +++ b/integration/fixtures/https/https_sni_default_cert.toml @@ -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] diff --git a/integration/fixtures/https/https_sni_strict.toml b/integration/fixtures/https/https_sni_strict.toml index f24b9cf3b..6cca5d576 100644 --- a/integration/fixtures/https/https_sni_strict.toml +++ b/integration/fixtures/https/https_sni_strict.toml @@ -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 diff --git a/integration/fixtures/https/rootcas/https.toml b/integration/fixtures/https/rootcas/https.toml index c3e903387..ef89ac863 100644 --- a/integration/fixtures/https/rootcas/https.toml +++ b/integration/fixtures/https/rootcas/https.toml @@ -44,4 +44,3 @@ fblo6RBxUQ== [[http.services.service1.LoadBalancer.Servers]] URL = "{{ .BackendHost }}" - Weight = 1 diff --git a/integration/fixtures/https/rootcas/https_with_file.toml b/integration/fixtures/https/rootcas/https_with_file.toml index 661e441a7..efdd2fb6e 100644 --- a/integration/fixtures/https/rootcas/https_with_file.toml +++ b/integration/fixtures/https/rootcas/https_with_file.toml @@ -29,4 +29,3 @@ rootCAs = [ "fixtures/https/rootcas/local.crt"] [[http.services.service1.LoadBalancer.Servers]] URL = "{{ .BackendHost }}" - Weight = 1 diff --git a/integration/fixtures/log_rotation_config.toml b/integration/fixtures/log_rotation_config.toml index 95dee4997..bc2e429ce 100644 --- a/integration/fixtures/log_rotation_config.toml +++ b/integration/fixtures/log_rotation_config.toml @@ -35,4 +35,3 @@ entryPoint = "api" [[http.services.service1.LoadBalancer.Servers]] URL = "http://127.0.0.1:8081" - Weight = 1 diff --git a/integration/fixtures/multiple_provider.toml b/integration/fixtures/multiple_provider.toml index d0bb8f653..6e8cc4979 100644 --- a/integration/fixtures/multiple_provider.toml +++ b/integration/fixtures/multiple_provider.toml @@ -30,4 +30,3 @@ level = "DEBUG" [[http.services.service-test.LoadBalancer.Servers]] URL = "http://{{ .IP }}" - Weight = 1 diff --git a/integration/fixtures/multiprovider.toml b/integration/fixtures/multiprovider.toml index cc03d5d1f..3184a5a1f 100644 --- a/integration/fixtures/multiprovider.toml +++ b/integration/fixtures/multiprovider.toml @@ -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" diff --git a/integration/fixtures/proxy-protocol/with.toml b/integration/fixtures/proxy-protocol/with.toml index 1d75abb4d..5f853093d 100644 --- a/integration/fixtures/proxy-protocol/with.toml +++ b/integration/fixtures/proxy-protocol/with.toml @@ -27,4 +27,3 @@ level = "DEBUG" [[http.services.service1.LoadBalancer.Servers]] URL = "http://{{.WhoamiIP}}" - Weight = 1 diff --git a/integration/fixtures/proxy-protocol/without.toml b/integration/fixtures/proxy-protocol/without.toml index 3baeae411..f4c12fcdd 100644 --- a/integration/fixtures/proxy-protocol/without.toml +++ b/integration/fixtures/proxy-protocol/without.toml @@ -27,4 +27,3 @@ level = "DEBUG" [[http.services.service1.LoadBalancer.Servers]] URL = "http://{{.WhoamiIP}}" - Weight = 1 diff --git a/integration/fixtures/ratelimit/simple.toml b/integration/fixtures/ratelimit/simple.toml index 12f588d29..d7508877e 100644 --- a/integration/fixtures/ratelimit/simple.toml +++ b/integration/fixtures/ratelimit/simple.toml @@ -36,4 +36,3 @@ level = "DEBUG" passHostHeader = true [[http.services.service1.LoadBalancer.Servers]] URL = "http://{{.Server1}}:80" - Weight = 1 diff --git a/integration/fixtures/reqacceptgrace.toml b/integration/fixtures/reqacceptgrace.toml index 260760b8e..61069237d 100644 --- a/integration/fixtures/reqacceptgrace.toml +++ b/integration/fixtures/reqacceptgrace.toml @@ -32,5 +32,4 @@ level = "DEBUG" [[http.services.service.LoadBalancer.Servers]] URL = "{{.Server}}" - Weight = 1 diff --git a/integration/fixtures/retry/simple.toml b/integration/fixtures/retry/simple.toml index ad94b47d1..44f4a2577 100644 --- a/integration/fixtures/retry/simple.toml +++ b/integration/fixtures/retry/simple.toml @@ -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 diff --git a/integration/fixtures/simple_stats.toml b/integration/fixtures/simple_stats.toml index 808a2635d..f2202d92c 100644 --- a/integration/fixtures/simple_stats.toml +++ b/integration/fixtures/simple_stats.toml @@ -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 diff --git a/integration/fixtures/tcp/mixed.toml b/integration/fixtures/tcp/mixed.toml index 3116d7df9..8a73f837c 100644 --- a/integration/fixtures/tcp/mixed.toml +++ b/integration/fixtures/tcp/mixed.toml @@ -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] diff --git a/integration/fixtures/tcp/non-tls-fallback.toml b/integration/fixtures/tcp/non-tls-fallback.toml index 99f2c51b8..37ff13045 100644 --- a/integration/fixtures/tcp/non-tls-fallback.toml +++ b/integration/fixtures/tcp/non-tls-fallback.toml @@ -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" diff --git a/integration/fixtures/timeout/forwarding_timeouts.toml b/integration/fixtures/timeout/forwarding_timeouts.toml index 4ceceb446..04d80e14f 100644 --- a/integration/fixtures/timeout/forwarding_timeouts.toml +++ b/integration/fixtures/timeout/forwarding_timeouts.toml @@ -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 diff --git a/integration/fixtures/tracing/simple.toml b/integration/fixtures/tracing/simple.toml index 955f1eebc..40428ddef 100644 --- a/integration/fixtures/tracing/simple.toml +++ b/integration/fixtures/tracing/simple.toml @@ -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 diff --git a/integration/fixtures/websocket/config.toml b/integration/fixtures/websocket/config.toml index fd7f3f9e1..5bd199180 100644 --- a/integration/fixtures/websocket/config.toml +++ b/integration/fixtures/websocket/config.toml @@ -25,4 +25,3 @@ level = "DEBUG" passHostHeader = true [[http.services.service1.LoadBalancer.Servers]] URL = "{{ .WebsocketServer }}" - Weight = 1 diff --git a/integration/fixtures/websocket/config_https.toml b/integration/fixtures/websocket/config_https.toml index 76de69636..a1e672c20 100644 --- a/integration/fixtures/websocket/config_https.toml +++ b/integration/fixtures/websocket/config_https.toml @@ -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" diff --git a/integration/healthcheck_test.go b/integration/healthcheck_test.go index 2d31f149e..13fc47860 100644 --- a/integration/healthcheck_test.go +++ b/integration/healthcheck_test.go @@ -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}) diff --git a/integration/resources/compose/access_log.yml b/integration/resources/compose/access_log.yml index 34eb5caa9..bd080630e 100644 --- a/integration/resources/compose/access_log.yml +++ b/integration/resources/compose/access_log.yml @@ -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: diff --git a/integration/rest_test.go b/integration/rest_test.go index 8e31b559c..86cad9d90 100644 --- a/integration/rest_test.go +++ b/integration/rest_test.go @@ -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", }, }, }, diff --git a/pkg/api/handler_test.go b/pkg/api/handler_test.go index 034ac9365..a6075ad4d 100644 --- a/pkg/api/handler_test.go +++ b/pkg/api/handler_test.go @@ -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", }, }, }, diff --git a/pkg/api/testdata/getrawdata.json b/pkg/api/testdata/getrawdata.json index 1a22d9496..97270da85 100644 --- a/pkg/api/testdata/getrawdata.json +++ b/pkg/api/testdata/getrawdata.json @@ -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", diff --git a/pkg/config/dyn_config.go b/pkg/config/dyn_config.go index b5dcedca6..8cf078a57 100644 --- a/pkg/config/dyn_config.go +++ b/pkg/config/dyn_config.go @@ -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" } diff --git a/pkg/config/runtime_test.go b/pkg/config/runtime_test.go index 415d156ae..11e14a7b2 100644 --- a/pkg/config/runtime_test.go +++ b/pkg/config/runtime_test.go @@ -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", }, }, }, diff --git a/pkg/metrics/prometheus_test.go b/pkg/metrics/prometheus_test.go index ada9d845c..fc32fc7a8 100644 --- a/pkg/metrics/prometheus_test.go +++ b/pkg/metrics/prometheus_test.go @@ -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"))), ), ), diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index 8bb6a83ec..4967c3d04 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -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} } diff --git a/pkg/provider/docker/config_test.go b/pkg/provider/docker/config_test.go index a6644d627..945b79dbb 100644 --- a/pkg/provider/docker/config_test.go +++ b/pkg/provider/docker/config_test.go @@ -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", }, }, }, diff --git a/pkg/provider/file/file_test.go b/pkg/provider/file/file_test.go index 2c1b90b8a..96d70f8a0 100644 --- a/pkg/provider/file/file_test.go +++ b/pkg/provider/file/file_test.go @@ -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 diff --git a/pkg/provider/kubernetes/crd/kubernetes.go b/pkg/provider/kubernetes/crd/kubernetes.go index 99c5833ba..d735450c4 100644 --- a/pkg/provider/kubernetes/crd/kubernetes.go +++ b/pkg/provider/kubernetes/crd/kubernetes.go @@ -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, }, } diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index 689552501..175b88e59 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -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, }, }, diff --git a/pkg/provider/kubernetes/crd/traefik/v1alpha1/ingressroute.go b/pkg/provider/kubernetes/crd/traefik/v1alpha1/ingressroute.go index 77e7b1534..a7b22f53f 100644 --- a/pkg/provider/kubernetes/crd/traefik/v1alpha1/ingressroute.go +++ b/pkg/provider/kubernetes/crd/traefik/v1alpha1/ingressroute.go @@ -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"` } diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 58e3322a9..b8a43f60a 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -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 diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index af9270738..388ed7ce7 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -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", }, }, }, diff --git a/pkg/provider/label/parser_test.go b/pkg/provider/label/parser_test.go index 60af8b4b1..7493a7044 100644 --- a/pkg/provider/label/parser_test.go +++ b/pkg/provider/label/parser_test.go @@ -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 { diff --git a/pkg/provider/marathon/config.go b/pkg/provider/marathon/config.go index e127b28be..81bbcc3cd 100644 --- a/pkg/provider/marathon/config.go +++ b/pkg/provider/marathon/config.go @@ -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 diff --git a/pkg/provider/marathon/config_test.go b/pkg/provider/marathon/config_test.go index 03832fe5e..bd0337baf 100644 --- a/pkg/provider/marathon/config_test.go +++ b/pkg/provider/marathon/config_test.go @@ -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", diff --git a/pkg/provider/rancher/config.go b/pkg/provider/rancher/config.go index 1e8e28c9e..76a6313d4 100644 --- a/pkg/provider/rancher/config.go +++ b/pkg/provider/rancher/config.go @@ -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)), }) } diff --git a/pkg/provider/rancher/config_test.go b/pkg/provider/rancher/config_test.go index 888756d89..88e60220a 100644 --- a/pkg/provider/rancher/config_test.go +++ b/pkg/provider/rancher/config_test.go @@ -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", }, }, }, diff --git a/pkg/server/router/router_test.go b/pkg/server/router/router_test.go index b31476d1d..eb86f64d9 100644 --- a/pkg/server/router/router_test.go +++ b/pkg/server/router/router_test.go @@ -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", }, }, } diff --git a/pkg/server/router/tcp/router_test.go b/pkg/server/router/tcp/router_test.go index c6543f008..a8b933a51 100644 --- a/pkg/server/router/tcp/router_test.go +++ b/pkg/server/router/tcp/router_test.go @@ -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", }, }, }, diff --git a/pkg/server/server_configuration_test.go b/pkg/server/server_configuration_test.go index 4c4d50008..a5d8b1fdc 100644 --- a/pkg/server/server_configuration_test.go +++ b/pkg/server/server_configuration_test.go @@ -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))), ), ) diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 634e349f0..75ea489df 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -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")), ), ) }, diff --git a/pkg/server/service/service.go b/pkg/server/service/service.go index 7383f517d..ad5cfceea 100644 --- a/pkg/server/service/service.go +++ b/pkg/server/service/service.go @@ -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) } diff --git a/pkg/server/service/service_test.go b/pkg/server/service/service_test.go index cf33471b3..c2064e62a 100644 --- a/pkg/server/service/service_test.go +++ b/pkg/server/service/service_test.go @@ -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{}, }, }, }, diff --git a/pkg/server/service/tcp/service_test.go b/pkg/server/service/tcp/service_test.go index 9693a1d74..aaac0877d 100644 --- a/pkg/server/service/tcp/service_test.go +++ b/pkg/server/service/tcp/service_test.go @@ -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", }, }, }, diff --git a/pkg/tcp/rr_load_balancer.go b/pkg/tcp/rr_load_balancer.go index c461b53c4..84fb63596 100644 --- a/pkg/tcp/rr_load_balancer.go +++ b/pkg/tcp/rr_load_balancer.go @@ -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") diff --git a/pkg/testhelpers/config.go b/pkg/testhelpers/config.go index 701b5e9f7..ba2ebfebd 100644 --- a/pkg/testhelpers/config.go +++ b/pkg/testhelpers/config.go @@ -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) {