Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit ec78575

Browse files
committed
remove duplicated routes in tcp section
1 parent 2ee28ad commit ec78575

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

haproxy/helper/backend_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def get_backend_routes(route_health_check, is_sticky, routes, routes_added, serv
2323
backend_routes = []
2424
for _service_alias, routes in routes.iteritems():
2525
if not service_alias or _service_alias == service_alias:
26-
address_add = []
26+
addresses_added = []
2727
for route in routes:
2828
# avoid adding those tcp routes adding http backends
2929
if route in routes_added:
3030
continue
3131
address = "%s:%s" % (route["addr"], route["port"])
32-
if address not in address_add:
33-
address_add.append(address)
32+
if address not in addresses_added:
33+
addresses_added.append(address)
3434
backend_route = ["server %s %s" % (route["container_name"], address)]
3535
if is_sticky:
3636
backend_route.append("cookie %s" % route["container_name"])

haproxy/helper/tcp_helper.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def parse_port_string(port, ssl_bind_string):
2727
def get_tcp_routes(details, routes, port, port_num):
2828
tcp_routes = []
2929
routes_added = []
30+
addresses_added = []
3031
if port != port_num and port != port_num + "/ssl":
3132
return tcp_routes, routes_added
3233

@@ -35,11 +36,15 @@ def get_tcp_routes(details, routes, port, port_num):
3536
if tcp_ports and port in tcp_ports:
3637
for route in routes:
3738
if route["port"] == port_num:
38-
tcp_route = ["server %s %s:%s" % (route["container_name"], route["addr"], route["port"])]
39-
health_check = get_healthcheck_string(details, _service_alias)
40-
tcp_route.append(health_check)
41-
tcp_routes.append(" ".join(tcp_route))
39+
address = "%s:%s" % (route["addr"], route["port"])
40+
if address not in addresses_added:
41+
addresses_added.append(address)
42+
tcp_route = ["server %s %s" % (route["container_name"], address)]
43+
health_check = get_healthcheck_string(details, _service_alias)
44+
tcp_route.append(health_check)
45+
tcp_routes.append(" ".join(tcp_route))
4246
routes_added.append(route)
47+
4348
return tcp_routes, routes_added
4449

4550

0 commit comments

Comments
 (0)