Skip to content

Commit

Permalink
Fix for multi-network stanza pods
Browse files Browse the repository at this point in the history
  • Loading branch information
NotChristianGarcia committed Aug 26, 2024
1 parent 003f7b3 commit 8d89c8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 13 additions & 5 deletions service/health_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,23 @@ def set_traefik_proxy():
if not isinstance(net_info, dict):
net_info = net_info.dict()

# name should be pods-tacc-tacc-mypod unless specified, if so
# then something like pods-tacc-tacc-mypod-mynet
if net_name != "default":
traefik_service_name = f"{pod.k8_name}-{net_name}"
else:
traefik_service_name = pod.k8_name

template_info = {"routing_port": net_info['port'],
"url": net_info['url']}
"url": net_info['url'],
"k8_service": pod.k8_name}
match net_info['protocol']:
case "tcp":
tcp_proxy_info[pod.k8_name] = template_info
tcp_proxy_info[traefik_service_name] = template_info
case "http":
http_proxy_info[pod.k8_name] = template_info
http_proxy_info[traefik_service_name] = template_info
case "postgres":
postgres_proxy_info[pod.k8_name] = template_info
postgres_proxy_info[traefik_service_name] = template_info
case "local_only":
# when users only need networking to connect to other pods in the same namespace
pass
Expand Down Expand Up @@ -268,4 +276,4 @@ def main():


if __name__ == '__main__':
main()
main()
9 changes: 5 additions & 4 deletions service/templates/traefik-template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ http:
customRequestHeaders:
host: "localhost:5000"
customResponseHeaders:
access-control-allow-origin: ""
host: "localhost:5000"
error-handler:
errors:
Expand Down Expand Up @@ -54,7 +55,7 @@ http:
{{ pname }}:
loadBalancer:
servers:
- url: http://{{ pname }}:{{ pdata.routing_port }}
- url: http://{{ pdata.k8_service }}:{{ pdata.routing_port }}
{% endfor %}

{% if tcp_proxy_info or postgres_proxy_info -%}
Expand Down Expand Up @@ -82,11 +83,11 @@ tcp:
{{ pname }}:
loadBalancer:
servers:
- address: {{ pname }}:{{ pdata.routing_port }}
- address: {{ pdata.k8_service }}:{{ pdata.routing_port }}
{% endfor %}
{% for pname, pdata in postgres_proxy_info.items() -%}
{{ pname }}:
loadBalancer:
servers:
- address: {{ pname }}:{{ pdata.routing_port }}
{% endfor %}
- address: {{ pdata.k8_service }}:{{ pdata.routing_port }}
{% endfor %}

0 comments on commit 8d89c8e

Please sign in to comment.