Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Update charm libraries (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <[email protected]>
  • Loading branch information
observability-noctua-bot and Github Actions authored Apr 10, 2024
1 parent cffeb7b commit c37cb68
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/charms/traefik_k8s/v1/ingress_per_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c37cb68

Please sign in to comment.