From c37cb68301c314b4c92b9a2e31070895c3aa6e4e Mon Sep 17 00:00:00 2001 From: Noctua Date: Wed, 10 Apr 2024 21:51:33 +0200 Subject: [PATCH] Update charm libraries (#50) Co-authored-by: Github Actions --- lib/charms/traefik_k8s/v1/ingress_per_unit.py | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/charms/traefik_k8s/v1/ingress_per_unit.py b/lib/charms/traefik_k8s/v1/ingress_per_unit.py index 987bf46..340001c 100644 --- a/lib/charms/traefik_k8s/v1/ingress_per_unit.py +++ b/lib/charms/traefik_k8s/v1/ingress_per_unit.py @@ -63,7 +63,7 @@ def _on_ingress_revoked(self, event: IngressPerUnitRevokedForUnitEvent): from typing import Any, Dict, Optional, Tuple, Union import yaml -from ops.charm import CharmBase, RelationBrokenEvent, RelationEvent +from ops.charm import CharmBase, RelationEvent from ops.framework import ( EventSource, Object, @@ -82,7 +82,7 @@ def _on_ingress_revoked(self, event: IngressPerUnitRevokedForUnitEvent): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 17 +LIBPATCH = 19 log = logging.getLogger(__name__) @@ -734,38 +734,37 @@ def _handle_relation(self, event: RelationEvent): # we calculate the diff between the urls we were aware of # before and those we know now previous_urls = self._stored.current_urls or {} # type: ignore - current_urls = ( - {} if isinstance(event, RelationBrokenEvent) else self._urls_from_relation_data - ) + + # since ops 2.10, breaking relations won't show up in self.model.relations, so we're safe + # in assuming all relations that are there are alive and well. + current_urls = self._urls_from_relation_data self._stored.current_urls = current_urls # type: ignore removed = previous_urls.keys() - current_urls.keys() # type: ignore changed = {a for a in current_urls if current_urls[a] != previous_urls.get(a)} # type: ignore this_unit_name = self.unit.name + # do not use self.relation in this context because if + # the event is relation-broken, self.relation might be None + relation = event.relation if self.listen_to in {"only-this-unit", "both"}: if this_unit_name in changed: - self.on.ready_for_unit.emit( # type: ignore - self.relation, current_urls[this_unit_name] - ) + self.on.ready_for_unit.emit(relation, current_urls[this_unit_name]) # type: ignore if this_unit_name in removed: - self.on.revoked_for_unit.emit(self.relation) # type: ignore + self.on.revoked_for_unit.emit(relation) # type: ignore if self.listen_to in {"all-units", "both"}: for unit_name in changed: - self.on.ready.emit( # type: ignore - self.relation, unit_name, current_urls[unit_name] - ) + self.on.ready.emit(relation, unit_name, current_urls[unit_name]) # type: ignore for unit_name in removed: - self.on.revoked.emit(self.relation, unit_name) # type: ignore + self.on.revoked.emit(relation, unit_name) # type: ignore self._publish_auto_data() def _handle_upgrade_or_leader(self, event): - if self.relations: - self._publish_auto_data() + self._publish_auto_data() def _publish_auto_data(self): if self._port: