Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compat with ops 2.10 #287

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/charms/traefik_k8s/v1/ingress_per_unit.py
PietroPasotti marked this conversation as resolved.
Show resolved Hide resolved
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 = 18

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -734,9 +734,10 @@ 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
Expand All @@ -750,7 +751,7 @@ def _handle_relation(self, event: RelationEvent):
)

if this_unit_name in removed:
self.on.revoked_for_unit.emit(self.relation) # type: ignore
self.on.revoked_for_unit.emit(event.relation) # type: ignore

if self.listen_to in {"all-units", "both"}:
for unit_name in changed:
Expand All @@ -759,7 +760,7 @@ def _handle_relation(self, event: RelationEvent):
)

for unit_name in removed:
self.on.revoked.emit(self.relation, unit_name) # type: ignore
self.on.revoked.emit(event.relation, unit_name) # type: ignore

self._publish_auto_data()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def get_app_names(self) -> List[str]:
if not self._charm.model.relations[self._relation_name]:
return []

app_names = list()
app_names = []
for relation in self._charm.model.relations[self._relation_name]:
app_names.append(relation.app.name)

Expand Down
Loading