Skip to content

Commit

Permalink
Safely normalize host ports when retrieving from docker
Browse files Browse the repository at this point in the history
(cherry picked from commit b38f169)
  • Loading branch information
sonicaj authored and bugclerk committed Dec 31, 2024
1 parent 73e4ad7 commit dbd7f2d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/middlewared/middlewared/plugins/apps/ix_apps/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,18 @@ def translate_resources_to_desired_workflow(app_resources: dict) -> dict:
if not host_config:
# This will happen for ports which are not exposed on the host side
continue
host_ports = []
for host_port in host_config:
try:
# We have seen that docker can report host port as an empty string or null
host_ports.append({'host_port': int(host_port['HostPort']), 'host_ip': host_port['HostIp']})
except (TypeError, ValueError):
continue

port_config = {
'container_port': int(container_port.split('/')[0]),
'protocol': container_port.split('/')[1],
'host_ports': [
{'host_port': int(host_port['HostPort']), 'host_ip': host_port['HostIp']}
for host_port in host_config
]
'host_ports': host_ports,
}
container_ports_config.append(port_config)

Expand Down

0 comments on commit dbd7f2d

Please sign in to comment.