From 27f5c9fc21e18dc9af5a33145b86dba1d62d04f8 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 14 Aug 2024 12:38:17 -0500 Subject: [PATCH 1/2] Handle errors which checking for a missing app. --- .../deploy/webapp/deploy_webapp_from_registry.py | 10 ++++++++-- stack_orchestrator/deploy/webapp/util.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index 9031e798..f27b62ee 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -278,9 +278,15 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ print(f"Skipping request {r.id}, we've already seen it.") continue - app = laconic.get_record(r.attributes.application) + try: + app = laconic.get_record(r.attributes.application) + except Exception as e: + print("ERROR: " + str(e)) + app = None + if not app: - print("Skipping request %s, cannot locate app." % r.id) + print(f"Skipping request {r.id}, cannot locate app.") + dump_known_requests(state_file, [r]) continue requested_name = r.attributes.dns diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index cc476656..5061566e 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -172,7 +172,7 @@ class LaconicRegistryClient: name_or_id, ] - parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args))] + parsed = [AttrDict(r) for r in json.loads(logged_cmd(self.log_file, *args)) if r] if len(parsed): self._add_to_cache(parsed) return parsed[0] -- 2.45.2 From e04631b4d5d987017b266d3fd1ad975997ef9768 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 14 Aug 2024 12:49:05 -0500 Subject: [PATCH 2/2] Defensively handle errors examining app requests. --- .../webapp/deploy_webapp_from_registry.py | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index f27b62ee..9626bf7b 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -274,40 +274,43 @@ def command(ctx, kube_config, laconic_config, image_registry, deployment_parent_ requests_by_name = {} skipped_by_name = {} for r in requests: - if r.id in previous_requests and previous_requests[r.id].get("status", "") != "RETRY": - print(f"Skipping request {r.id}, we've already seen it.") - continue - + status = None try: + if r.id in previous_requests and previous_requests[r.id].get("status", "") != "RETRY": + print(f"Skipping request {r.id}, we've already seen it.") + continue + app = laconic.get_record(r.attributes.application) + if not app: + print(f"Skipping request {r.id}, cannot locate app.") + status = "SEEN" + continue + + requested_name = r.attributes.dns + if not requested_name: + requested_name = generate_hostname_for_app(app) + print("Generating name %s for request %s." % (requested_name, r.id)) + + if requested_name in skipped_by_name or requested_name in requests_by_name: + print("Ignoring request %s, it has been superseded." % r.id) + continue + + if skip_by_tag(r, include_tags, exclude_tags): + print("Skipping request %s, filtered by tag (include %s, exclude %s, present %s)" % (r.id, + include_tags, + exclude_tags, + r.attributes.tags)) + skipped_by_name[requested_name] = r + continue + + print("Found request %s to run application %s on %s." % (r.id, r.attributes.application, requested_name)) + requests_by_name[requested_name] = r except Exception as e: - print("ERROR: " + str(e)) - app = None - - if not app: - print(f"Skipping request {r.id}, cannot locate app.") - dump_known_requests(state_file, [r]) - continue - - requested_name = r.attributes.dns - if not requested_name: - requested_name = generate_hostname_for_app(app) - print("Generating name %s for request %s." % (requested_name, r.id)) - - if requested_name in skipped_by_name or requested_name in requests_by_name: - print("Ignoring request %s, it has been superseded." % r.id) - continue - - if skip_by_tag(r, include_tags, exclude_tags): - print("Skipping request %s, filtered by tag (include %s, exclude %s, present %s)" % (r.id, - include_tags, - exclude_tags, - r.attributes.tags)) - skipped_by_name[requested_name] = r - continue - - print("Found request %s to run application %s on %s." % (r.id, r.attributes.application, requested_name)) - requests_by_name[requested_name] = r + print(f"ERROR examining request {r.id}: " + str(e)) + status = "ERROR" + finally: + if status: + dump_known_requests(state_file, [r], status) # Find deployments. deployments = laconic.app_deployments() -- 2.45.2