Skip to content

Commit

Permalink
Support aliasing the redis relation
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas committed Nov 14, 2023
1 parent f460c6e commit a04fab4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/charms/redis_k8s/v0/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version.
LIBPATCH = 3
LIBPATCH = 4

logger = logging.getLogger(__name__)

DEFAULT_REALTION_NAME = "redis"

class RedisRelationUpdatedEvent(EventBase):
"""An event for the redis relation having been updated."""
Expand All @@ -60,9 +61,9 @@ class RedisRelationCharmEvents(CharmEvents):


class RedisRequires(Object):
def __init__(self, charm, _stored):
def __init__(self, charm, _stored, relation_name: str = DEFAULT_REALTION_NAME):
"""A class implementing the redis requires relation."""
super().__init__(charm, "redis")
super().__init__(charm, relation_name)
self.framework.observe(charm.on.redis_relation_joined, self._on_relation_changed)
self.framework.observe(charm.on.redis_relation_changed, self._on_relation_changed)
self.framework.observe(charm.on.redis_relation_broken, self._on_relation_broken)
Expand Down Expand Up @@ -91,9 +92,9 @@ def _on_relation_broken(self, event):


class RedisProvides(Object):
def __init__(self, charm, port):
def __init__(self, charm, port, relation_name: str = DEFAULT_REALTION_NAME):
"""A class implementing the redis provides relation."""
super().__init__(charm, "redis")
super().__init__(charm, relation_name)
self.framework.observe(charm.on.redis_relation_changed, self._on_relation_changed)
self._port = port
self._charm = charm
Expand Down

0 comments on commit a04fab4

Please sign in to comment.