-
Notifications
You must be signed in to change notification settings - Fork 20
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-3562] Don't block on missing Postgresql version #626
Changes from all commits
2dc3c1e
d711468
74dbdc4
97c6b46
e05981f
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 |
---|---|---|
|
@@ -96,7 +96,13 @@ def _on_relation_changed(self, event: RelationChangedEvent) -> None: | |
|
||
logger.warning(f"DEPRECATION WARNING - `{self.relation_name}` is a legacy interface") | ||
|
||
self.set_up_relation(event.relation) | ||
if ( | ||
not self.set_up_relation(event.relation) | ||
and self.charm.unit.status.message | ||
== f"Failed to initialize {self.relation_name} relation" | ||
): | ||
event.defer() | ||
return | ||
|
||
def _check_exist_current_relation(self) -> bool: | ||
for r in self.charm.client_relations: | ||
|
@@ -152,12 +158,9 @@ def set_up_relation(self, relation: Relation) -> bool: | |
self.charm.unit.status = BlockedStatus(ROLES_BLOCKING_MESSAGE) | ||
return False | ||
|
||
database = relation.data.get(relation.app, {}).get("database") | ||
if not database: | ||
if not (database := relation.data.get(relation.app, {}).get("database")): | ||
for unit in relation.units: | ||
unit_database = relation.data.get(unit, {}).get("database") | ||
if unit_database: | ||
database = unit_database | ||
if database := relation.data.get(unit, {}).get("database"): | ||
break | ||
|
||
if not database: | ||
|
@@ -207,31 +210,40 @@ def set_up_relation(self, relation: Relation) -> bool: | |
) | ||
) | ||
|
||
postgresql_version = None | ||
try: | ||
postgresql_version = self.charm.postgresql.get_postgresql_version() | ||
except PostgreSQLGetPostgreSQLVersionError: | ||
logger.exception( | ||
"Failed to retrieve the PostgreSQL version to initialise/update %s relation" | ||
% self.relation_name | ||
) | ||
|
||
Comment on lines
+213
to
+221
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. K8S charm will not update the endpoints as aggressively as VM. This will be reran only on config change. Should I try add something to update status? 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. Is it a time for Pebble Notices and stop relying update-status? 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. If it's possible to avoid calls to |
||
# Set the data in both application and unit data bag. | ||
# It's needed to run this logic on every relation changed event | ||
# setting the data again in the databag, otherwise the application charm that | ||
# is connecting to this database will receive a "database gone" event from the | ||
# old PostgreSQL library (ops-lib-pgsql) and the connection between the | ||
# application and this charm will not work. | ||
for databag in [application_relation_databag, unit_relation_databag]: | ||
updates = { | ||
"allowed-subnets": self._get_allowed_subnets(relation), | ||
"allowed-units": self._get_allowed_units(relation), | ||
"host": self.charm.endpoint, | ||
"master": primary, | ||
"port": DATABASE_PORT, | ||
"standbys": standbys, | ||
"version": self.charm.postgresql.get_postgresql_version(), | ||
"user": user, | ||
"password": password, | ||
"database": database, | ||
"extensions": ",".join(required_extensions), | ||
} | ||
databag.update(updates) | ||
updates = { | ||
"allowed-subnets": self._get_allowed_subnets(relation), | ||
"allowed-units": self._get_allowed_units(relation), | ||
"host": self.charm.endpoint, | ||
"master": primary, | ||
"port": DATABASE_PORT, | ||
"standbys": standbys, | ||
"user": user, | ||
"password": password, | ||
"database": database, | ||
"extensions": ",".join(required_extensions), | ||
} | ||
if postgresql_version: | ||
updates["version"] = postgresql_version | ||
application_relation_databag.update(updates) | ||
unit_relation_databag.update(updates) | ||
Comment on lines
+242
to
+243
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. So that that mccabe doesn't complain. |
||
except ( | ||
PostgreSQLCreateDatabaseError, | ||
PostgreSQLCreateUserError, | ||
PostgreSQLGetPostgreSQLVersionError, | ||
): | ||
self.charm.unit.status = BlockedStatus( | ||
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. We should most probably defer here. Should I change this as well? 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. I think a |
||
f"Failed to initialize {self.relation_name} relation" | ||
|
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.
Charm should be unblocked by
_update_unit_status
if set_up_relation succeeds.