-
Notifications
You must be signed in to change notification settings - Fork 10
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
[DPE-4772] Subordinate scale up #180
Changes from all commits
708c142
65ef261
139a17a
bf60728
bd46cf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent): | |
|
||
# Increment this PATCH version before using `charmcraft publish-lib` or reset | ||
# to 0 if you are raising the major API version | ||
LIBPATCH = 37 | ||
LIBPATCH = 38 | ||
|
||
PYDEPS = ["ops>=2.0.0"] | ||
|
||
|
@@ -2606,6 +2606,16 @@ def set_version(self, relation_id: int, version: str) -> None: | |
""" | ||
self.update_relation_data(relation_id, {"version": version}) | ||
|
||
def set_subordinated(self, relation_id: int) -> None: | ||
"""Raises the subordinated flag in the application relation databag. | ||
|
||
The flag will be used to evaluate additional checks before emitting provider events. | ||
|
||
Args: | ||
relation_id: the identifier for a particular relation. | ||
""" | ||
self.update_relation_data(relation_id, {"subordinated": "true"}) | ||
|
||
|
||
class DatabaseProviderEventHandlers(EventHandlers): | ||
"""Provider-side of the database relation handlers.""" | ||
|
@@ -2842,6 +2852,24 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None: | |
|
||
def _on_relation_changed_event(self, event: RelationChangedEvent) -> None: | ||
"""Event emitted when the database relation has changed.""" | ||
is_subordinate = False | ||
remote_unit_data = None | ||
for key in event.relation.data.keys(): | ||
if isinstance(key, Unit) and not key.name.startswith(self.charm.app.name): | ||
remote_unit_data = event.relation.data[key] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should only have one remote unit in case of subordinated relation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As commented on the related PR: canonical/pgbouncer-operator#274 (comment) This is kind of a "hack" over the concept pf the lib, where cross-charm relations were strictly using I've opened issue #182 and I try to address it in the near future (right after mid-cycle) |
||
elif isinstance(key, Application) and key.name != self.charm.app.name: | ||
is_subordinate = event.relation.data[key].get("subordinated") == "true" | ||
|
||
if is_subordinate: | ||
# Check that provider units have joined. | ||
if not remote_unit_data: | ||
logger.debug("No provider units are available.") | ||
return | ||
|
||
if remote_unit_data.get("state") != "ready": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. who/where does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subordinate provider sets it when the unit is ready. |
||
logger.debug("Subordinate provider unit not ready.") | ||
return | ||
|
||
# Check which data has changed to emit customs events. | ||
diff = self._diff(event) | ||
dragomirp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper to set the application level flag. If set the Requirer will do the additional subordination checks.