From 41733208da252dc41db263203406d86229917dd9 Mon Sep 17 00:00:00 2001 From: Luca Bello <36242061+lucabello@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:40:21 +0100 Subject: [PATCH] fix race condition in privkey generation (#76) * fix race condition in privkey generation * fix static checks in other libs * tox fmt --- .../v0/kubernetes_compute_resources_patch.py | 8 ++++---- .../observability_libs/v0/metrics_endpoint_discovery.py | 4 ++-- lib/charms/observability_libs/v1/cert_handler.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/charms/observability_libs/v0/kubernetes_compute_resources_patch.py b/lib/charms/observability_libs/v0/kubernetes_compute_resources_patch.py index a6ad4df..2ab8a22 100644 --- a/lib/charms/observability_libs/v0/kubernetes_compute_resources_patch.py +++ b/lib/charms/observability_libs/v0/kubernetes_compute_resources_patch.py @@ -133,7 +133,7 @@ def setUp(self, *unused): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 6 +LIBPATCH = 7 _Decimal = Union[Decimal, float, str, int] # types that are potentially convertible to Decimal @@ -364,7 +364,7 @@ def is_patched(self, resource_reqs: ResourceRequirements) -> bool: Returns: bool: A boolean indicating if the service patch has been applied. """ - return equals_canonically(self.get_templated(), resource_reqs) + return equals_canonically(self.get_templated(), resource_reqs) # pyright: ignore def get_templated(self) -> Optional[ResourceRequirements]: """Returns the resource limits specified in the StatefulSet template.""" @@ -397,8 +397,8 @@ def is_ready(self, pod_name, resource_reqs: ResourceRequirements): self.get_templated(), self.get_actual(pod_name), ) - return self.is_patched(resource_reqs) and equals_canonically( - resource_reqs, self.get_actual(pod_name) + return self.is_patched(resource_reqs) and equals_canonically( # pyright: ignore + resource_reqs, self.get_actual(pod_name) # pyright: ignore ) def apply(self, resource_reqs: ResourceRequirements) -> None: diff --git a/lib/charms/observability_libs/v0/metrics_endpoint_discovery.py b/lib/charms/observability_libs/v0/metrics_endpoint_discovery.py index 7864ef9..d77962e 100644 --- a/lib/charms/observability_libs/v0/metrics_endpoint_discovery.py +++ b/lib/charms/observability_libs/v0/metrics_endpoint_discovery.py @@ -62,7 +62,7 @@ def _on_endpoints_change(self, event): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 6 +LIBPATCH = 7 # File path where metrics endpoint change data is written for exchange # between the discovery process and the materialised event. @@ -215,7 +215,7 @@ def main(): target_ports = [] for c in filter(lambda c: c.ports is not None, entity.spec.containers): # pyright: ignore - for p in filter(lambda p: p.name == "metrics", c.ports): + for p in filter(lambda p: p.name == "metrics", c.ports): # pyright: ignore target_ports.append("*:{}".format(p.containerPort)) payload = { diff --git a/lib/charms/observability_libs/v1/cert_handler.py b/lib/charms/observability_libs/v1/cert_handler.py index 48da001..c2217df 100644 --- a/lib/charms/observability_libs/v1/cert_handler.py +++ b/lib/charms/observability_libs/v1/cert_handler.py @@ -208,6 +208,7 @@ def _on_config_changed(self, _): if not relation: return + self._generate_privkey() self._generate_csr(renew=True) def _generate_csr(