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

Commit 2ee28ad

Browse files
committed
fix the crash running with compose v1
1 parent 64c0b5e commit 2ee28ad

4 files changed

Lines changed: 21 additions & 25 deletions

File tree

haproxy/helper/backend_helper.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@ 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 = []
2627
for route in routes:
2728
# avoid adding those tcp routes adding http backends
2829
if route in routes_added:
2930
continue
31+
address = "%s:%s" % (route["addr"], route["port"])
32+
if address not in address_add:
33+
address_add.append(address)
34+
backend_route = ["server %s %s" % (route["container_name"], address)]
35+
if is_sticky:
36+
backend_route.append("cookie %s" % route["container_name"])
3037

31-
backend_route = ["server %s %s:%s" % (route["container_name"], route["addr"], route["port"])]
32-
if is_sticky:
33-
backend_route.append("cookie %s" % route["container_name"])
38+
if route_health_check:
39+
backend_route.append(route_health_check)
3440

35-
if route_health_check:
36-
backend_route.append(route_health_check)
41+
backend_routes.append(" ".join(backend_route))
3742

38-
backend_routes.append(" ".join(backend_route))
3943
return sorted(backend_routes)
4044

4145

haproxy/parser/base_parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ def _merge_services_with_same_vhost(self):
2424
self.service_aliases.remove(service_alias)
2525
del self.details[service_alias]
2626

27-
for route in self.routes[service_alias]:
28-
if services_with_same_vhost[service_alias] not in self. routes:
29-
self.routes[services_with_same_vhost[service_alias]] = [route]
30-
else:
31-
self.routes[services_with_same_vhost[service_alias]].append(route)
32-
del self.routes[service_alias]
27+
if service_alias in self.routes:
28+
for route in self.routes[service_alias]:
29+
if service_alias in services_with_same_vhost and \
30+
services_with_same_vhost[service_alias] in self.routes:
31+
self.routes[services_with_same_vhost[service_alias]].append(route)
32+
del self.routes[service_alias]
3333

3434
vhosts = []
3535
for vhost in self.vhosts:

haproxy/parser/legacy_link_parser.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,10 @@ def _parse_routes(details, envvars):
6666
route.update({"container_name": container_name})
6767
exclude_ports = details.get(service_alias, {}).get("exclude_ports")
6868
if not exclude_ports or (exclude_ports and route["port"] not in exclude_ports):
69-
route_added = False
70-
for _, rs in routes.iteritems():
71-
for r in rs:
72-
if route['proto'] == r['proto'] and \
73-
route['port'] == r['port'] and \
74-
route['addr'] == r['addr']:
75-
route_added = True
76-
break
77-
if not route_added:
78-
if service_alias in routes:
79-
routes[service_alias].append(route)
80-
else:
81-
routes[service_alias] = [route]
69+
if service_alias in routes:
70+
routes[service_alias].append(route)
71+
else:
72+
routes[service_alias] = [route]
8273
return routes
8374

8475

tests/unit/parser/test_legacy_link_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_parse_routes(self):
116116
}
117117

118118
routes = {'WORLD': [{'container_name': 'WORLD_1', 'proto': 'tcp', 'port': '80', 'addr': '10.7.0.3'}],
119+
'HELLO': [{'container_name': 'HELLO_1', 'proto': 'tcp', 'port': '80', 'addr': '10.7.0.1',}],
119120
'DUPLICATED': [{'container_name': 'DUPLICATED', 'proto': 'tcp', 'port': '80', 'addr': '10.7.0.1'}]}
120121
self.assertEqual(routes, specs._parse_routes(details, envvars))
121122

0 commit comments

Comments
 (0)