Skip to content

Commit

Permalink
Separately report images being used by apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Qubad786 committed Aug 2, 2024
1 parent 6eea579 commit 45ae11a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/apps/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Config:
'app_query',
Str('name'),
Str('id'),
Str('state'),
Str('state', enum=['STOPPED', 'DEPLOYING', 'RUNNING']),
Bool('upgrade_available'),
Str('human_version'),
Str('version'),
Expand All @@ -52,7 +52,7 @@ class Config:
Str('service_name'),
Str('image'),
List('port_config'),
Str('state'),
Str('state', enum=['running', 'starting', 'exited']),
List('volume_mounts'),
)]),
List('volumes', items=[Dict(
Expand Down
8 changes: 7 additions & 1 deletion src/middlewared/middlewared/plugins/apps/ix_apps/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def get_default_workload_values() -> dict:
'used_ports': [],
'container_details': [], # This would contain service name and image in use
'volumes': [], # This would be docker volumes
'images': [],
}


Expand All @@ -140,10 +141,12 @@ def translate_resources_to_desired_workflow(app_resources: dict) -> dict:
# Container mounts
workloads = get_default_workload_values()
volumes = set()
images = set()
workloads['containers'] = len(app_resources['containers'])
for container in app_resources['containers']:
service_name = container['Config']['Labels'][COMPOSE_SERVICE_KEY]
container_ports_config = []
images.add(container['Config']['Image'])
for container_port, host_config in container.get('NetworkSettings', {}).get('Ports', {}).items():
if not host_config:
# This will happen for ports which are not exposed on the host side
Expand Down Expand Up @@ -186,5 +189,8 @@ def translate_resources_to_desired_workflow(app_resources: dict) -> dict:
workloads['used_ports'].extend(container_ports_config)
volumes.update(volume_mounts)

workloads['volumes'] = [v.__dict__ for v in volumes]
workloads.update({
'images': list(images),
'volumes': [v.__dict__ for v in volumes],
})
return workloads

0 comments on commit 45ae11a

Please sign in to comment.