From 816cbf6becedda6556448b362c738d50df7a8f73 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Tue, 22 Oct 2024 09:28:04 +0200 Subject: [PATCH] move workload allowed to start check --- src/abstract_charm.py | 10 +++++++--- src/workload.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/abstract_charm.py b/src/abstract_charm.py index b6b7fab5e..d6b736756 100644 --- a/src/abstract_charm.py +++ b/src/abstract_charm.py @@ -277,12 +277,12 @@ def reconcile(self, event=None) -> None: # noqa: C901 exposed_read_only_endpoint=self._exposed_read_only_endpoint, shell=workload_.shell, ) - # todo: consider moving `self.refresh.workload_allowed_to_start` inside `workload._reconcile()` - if workload_.container_ready and self.refresh.workload_allowed_to_start: + if workload_.container_ready: workload_.reconcile( event=event, tls=self._tls_certificate_saved, unit_name=self.unit.name, + workload_allowed_to_start=self.refresh.workload_allowed_to_start, exporter_config=self._cos_exporter_config(event), key=self._tls_key, certificate=self._tls_certificate, @@ -297,7 +297,11 @@ def reconcile(self, event=None) -> None: # noqa: C901 self.refresh.next_unit_allowed_to_refresh = True # TODO add comment about unit started for scale up case since start event will fire after relation created # TODO add checks to reconcile debug log - elif workload_.status == ops.WaitingStatus() and self._unit_started.exists(): + elif ( + self.refresh.workload_allowed_to_start + and workload_.status == ops.WaitingStatus() + and self._unit_started.exists() + ): if self._database_requires.does_relation_exist(event): # Waiting for relation-changed event before starting workload pass diff --git a/src/workload.py b/src/workload.py index 33131e7bd..8fc6827d9 100644 --- a/src/workload.py +++ b/src/workload.py @@ -160,6 +160,7 @@ def reconcile( event, tls: bool, unit_name: str, + workload_allowed_to_start: bool, exporter_config: "relations.cos.ExporterConfig", key: str = None, certificate: str = None, @@ -362,12 +363,26 @@ def reconcile( event, tls: bool, unit_name: str, + workload_allowed_to_start: bool, exporter_config: "relations.cos.ExporterConfig", key: str = None, certificate: str = None, certificate_authority: str = None, ) -> None: """Reconcile all workloads (router, exporter, tls).""" + if not workload_allowed_to_start: + super().reconcile( + event=event, + tls=tls, + unit_name=unit_name, + workload_allowed_to_start=workload_allowed_to_start, + exporter_config=exporter_config, + key=key, + certificate=certificate, + certificate_authority=certificate_authority, + ) + return + if tls and not (key and certificate and certificate_authority): raise ValueError( "`key`, `certificate`, and `certificate_authority` arguments required when tls=True"