From 9db46a04e6e337e38b3e9898a7c823186a8818af Mon Sep 17 00:00:00 2001 From: Marcell Nagy Date: Wed, 20 Mar 2024 09:31:25 +0000 Subject: [PATCH] Fix docker ps labels format issue --- src/edge_containers_cli/cmds/local_commands.py | 8 ++++++++ tests/data/local.yaml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/edge_containers_cli/cmds/local_commands.py b/src/edge_containers_cli/cmds/local_commands.py index fa4bef90..fbec1609 100644 --- a/src/edge_containers_cli/cmds/local_commands.py +++ b/src/edge_containers_cli/cmds/local_commands.py @@ -180,6 +180,14 @@ def ps(self, all: bool, wide: bool): for line in str(result_json).strip().split("\n"): services_dicts.append(json.load(StringIO(line))) + # Docker returns labels as a single string "key0=x,key1=y" + for service_dict in services_dicts: + labels_list = service_dict["Labels"].split(",") + labels_dict = { + entry[0].split("="): entry[1].split("=") for entry in labels_list + } + service_dict["Labels"] = labels_dict + if not services_dicts: if all_arg: print("No deployed services found") diff --git a/tests/data/local.yaml b/tests/data/local.yaml index 721eaa5e..f8e2ce92 100644 --- a/tests/data/local.yaml +++ b/tests/data/local.yaml @@ -105,7 +105,7 @@ ps: { "CreatedAt":"", "Image": "", - "Labels":{"version":""}, + "Labels":"is_IOC=true,version=0", "Names":[""], "State":"", "Restarts":""