From 424f8a77019b3840f19c920ae3c815f2f1834b8e Mon Sep 17 00:00:00 2001 From: Marcell Nagy Date: Wed, 28 Aug 2024 15:13:37 +0000 Subject: [PATCH] Update argocd backend to match new charts --- src/edge_containers_cli/cmds/argo_commands.py | 46 +++++++++---------- tests/data/argocd.yaml | 4 +- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/edge_containers_cli/cmds/argo_commands.py b/src/edge_containers_cli/cmds/argo_commands.py index 56c25b11..f0c5b86d 100644 --- a/src/edge_containers_cli/cmds/argo_commands.py +++ b/src/edge_containers_cli/cmds/argo_commands.py @@ -54,16 +54,14 @@ def restart(self, service_name): def start(self, service_name): self._check_service(service_name) - cmd = ( - f"argocd app set {self.target} " f"-p services.{service_name}.enabled=true" - ) + project, app = extract_project_app(self.target) + cmd = f"argocd app set {project}/{service_name} -p global.enabled=true" shell.run_command(cmd, skip_on_dryrun=True) def stop(self, service_name): self._check_service(service_name) - cmd = ( - f"argocd app set {self.target} " f"-p services.{service_name}.enabled=false" - ) + project, app = extract_project_app(self.target) + cmd = f"argocd app set {project}/{service_name} -p global.enabled=false" shell.run_command(cmd, skip_on_dryrun=True) def _get_logs(self, service_name, prev) -> str: @@ -106,25 +104,25 @@ def _get_services(self, running_only) -> ServicesDataFrame: ) for resource_manifest in mani_resp.split("---")[1:]: manifest = YAML(typ="safe").load(resource_manifest) - time_stamp = datetime.strptime( - manifest["metadata"]["creationTimestamp"], - "%Y-%m-%dT%H:%M:%SZ", - ) - try: - if manifest["metadata"]["name"] == name: + kind = manifest["kind"] + resource_name = manifest["metadata"]["name"] + if kind == "StatefulSet" and resource_name == name: + try: is_ready = bool(manifest["status"]["readyReplicas"]) - except (KeyError, TypeError): # Not ready if doesnt exist - continue - - # Fill app data - service_data["name"].append(name) - service_data["version"].append( - app["spec"]["source"]["targetRevision"] - ) - service_data["ready"].append(is_ready) - service_data["deployed"].append( - datetime.strftime(time_stamp, TIME_FORMAT) - ) + except (KeyError, TypeError): # Not ready if doesnt exist + is_ready = False + time_stamp = datetime.strptime( + manifest["metadata"]["creationTimestamp"], + "%Y-%m-%dT%H:%M:%SZ", + ) + service_data["name"].append(name) + service_data["version"].append( + app["spec"]["source"]["targetRevision"] + ) + service_data["ready"].append(is_ready) + service_data["deployed"].append( + datetime.strftime(time_stamp, TIME_FORMAT) + ) services_df = polars.from_dict(service_data) diff --git a/tests/data/argocd.yaml b/tests/data/argocd.yaml index 32b851b4..19b01a2e 100644 --- a/tests/data/argocd.yaml +++ b/tests/data/argocd.yaml @@ -37,9 +37,9 @@ restart: rsp: "" start: - - cmd: argocd app set project/bl01t -p services.bl01t-ea-test-01.enabled=true + - cmd: argocd app set project/bl01t-ea-test-01 -p global.enabled=true rsp: "" stop: - - cmd: argocd app set project/bl01t -p services.bl01t-ea-test-01.enabled=false + - cmd: argocd app set project/bl01t-ea-test-01 -p global.enabled=false rsp: ""