Skip to content

Commit 0ddebc1

Browse files
committed
Changed the router to default to roundrobin with multiple services
If the route is associated with multiple services then we will set the default load balance policy to RoundRobin if no policy is set with an annotation or as a global default with an environment variable. Without this change the user would need to both set the services, weights, and then set an annotation to change the default balancing algorithm... which people almost always forgot to do. For bug 1416869 (https://bugzilla.redhat.com/show_bug.cgi?id=1416869)
1 parent cfb50d9 commit 0ddebc1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

images/router/haproxy/conf/haproxy-config.template

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ backend be_sni
153153

154154
frontend fe_sni
155155
# terminate ssl on edge
156-
bind 127.0.0.1:{{env "ROUTER_SERVICE_SNI_PORT" "10444"}} ssl no-sslv3 {{ if (len .DefaultCertificate) gt 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} crt-list /var/lib/haproxy/conf/cert_config.map accept-proxy
156+
bind 127.0.0.1:{{env "ROUTER_SERVICE_SNI_PORT" "10444"}} ssl no-sslv3 {{ if gt (len .DefaultCertificate) 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} crt-list /var/lib/haproxy/conf/cert_config.map accept-proxy
157157
mode http
158158

159159
# check re-encrypt backends first - from most specific to general path.
@@ -187,7 +187,7 @@ backend be_no_sni
187187

188188
frontend fe_no_sni
189189
# terminate ssl on edge
190-
bind 127.0.0.1:{{env "ROUTER_SERVICE_NO_SNI_PORT" "10443"}} ssl no-sslv3 {{ if (len .DefaultCertificate) gt 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} accept-proxy
190+
bind 127.0.0.1:{{env "ROUTER_SERVICE_NO_SNI_PORT" "10443"}} ssl no-sslv3 {{ if gt (len .DefaultCertificate) 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} accept-proxy
191191
mode http
192192

193193
# check re-encrypt backends first - path or host based.
@@ -255,7 +255,7 @@ backend be_edge_http_{{$cfgIdx}}
255255
{{ if (matchPattern "roundrobin|leastconn|source" (env "ROUTER_LOAD_BALANCE_ALGORITHM" "")) }}
256256
balance {{ env "ROUTER_LOAD_BALANCE_ALGORITHM" "leastconn"}}
257257
{{ else }}
258-
balance leastconn
258+
balance {{ if gt (len $cfg.ServiceUnitNames) 1 }}roundrobin{{ else }}leastconn{{ end }}
259259
{{ end }}
260260
{{ end }}
261261
{{ with $value := index $cfg.Annotations "haproxy.router.openshift.io/timeout"}}
@@ -337,7 +337,11 @@ backend be_tcp_{{$cfgIdx}}
337337
balance {{ $balanceAlgo }}
338338
{{ end }}
339339
{{ else }}
340-
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
340+
{{ if (matchPattern "roundrobin|leastconn|source" (env "ROUTER_TCP_BALANCE_SCHEME" "")) }}
341+
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source"}}
342+
{{ else }}
343+
balance {{ if gt (len $cfg.ServiceUnitNames) 1 }}roundrobin{{ else }}source{{ end }}
344+
{{ end }}
341345
{{ end }}
342346
{{ with $value := index $cfg.Annotations "haproxy.router.openshift.io/timeout"}}
343347
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
@@ -403,7 +407,7 @@ backend be_secure_{{$cfgIdx}}
403407
{{ if (matchPattern "roundrobin|leastconn|source" (env "ROUTER_LOAD_BALANCE_ALGORITHM" "")) }}
404408
balance {{ env "ROUTER_LOAD_BALANCE_ALGORITHM" "leastconn"}}
405409
{{ else }}
406-
balance leastconn
410+
balance {{ if gt (len $cfg.ServiceUnitNames) 1 }}roundrobin{{ else }}leastconn{{ end }}
407411
{{ end }}
408412
{{ end }}
409413
{{ with $value := index $cfg.Annotations "haproxy.router.openshift.io/timeout"}}

test/extended/testdata/weighted-router.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ items:
4646
labels:
4747
test: router
4848
select: weighted
49-
annotations:
50-
haproxy.router.openshift.io/balance: roundrobin
5149
spec:
5250
host: weighted.example.com
5351
to:
@@ -69,8 +67,6 @@ items:
6967
labels:
7068
test: router
7169
select: weighted
72-
annotations:
73-
haproxy.router.openshift.io/balance: roundrobin
7470
spec:
7571
host: zeroweight.example.com
7672
to:

0 commit comments

Comments
 (0)