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

chore(charm): Update Redis relation to be able to use HA #8

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion paas_app_charmer/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,29 @@ def _create_charm_state(self) -> CharmState:
for k, v in charm_config.items()
},
)
redis_url = None
if self._redis:
relation = self.model.get_relation(self._redis.relation_name)
if relation:
relation_app_data = relation.data[relation.app]
relation_unit_data = self._redis.relation_data
if relation_unit_data:
try:
redis_hostname = str(
relation_app_data.get("leader-host", relation_unit_data["hostname"])
)
redis_port = int(relation_unit_data["port"])
redis_url = f"redis://{redis_hostname}:{redis_port}"
except KeyError:
redis_url = None

return CharmState.from_charm(
config=config,
framework=self._framework_name,
framework_config=self.get_framework_config(),
secret_storage=self._secret_storage,
database_requirers=self._database_requirers,
redis_uri=self._redis.url if self._redis is not None else None,
redis_uri=redis_url,
s3_connection_info=self._s3.get_s3_connection_info() if self._s3 else None,
saml_relation_data=saml_relation_data,
rabbitmq_uri=self._rabbitmq.rabbitmq_uri() if self._rabbitmq else None,
Expand Down
Loading