Skip to content

Commit 8030851

Browse files
committed
handling different versions of Postgres of unit
1 parent 18211ed commit 8030851

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/charm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292

9393
PRIMARY_NOT_REACHABLE_MESSAGE = "waiting for primary to be reachable from this unit"
9494
EXTENSIONS_DEPENDENCY_MESSAGE = "Unsatisfied plugin dependencies. Please check the logs"
95+
DIFFERENT_VERSIONS_PSQL_BLOCKING_MESSAGE = (
96+
"Please select the correct version of postgresql to use. No need to use different versions of postgresql."
97+
)
9598

9699
Scopes = Literal[APP_SCOPE, UNIT_SCOPE]
97100

@@ -466,6 +469,10 @@ def _on_peer_relation_changed(self, event: HookEvent):
466469
event.defer()
467470
return
468471

472+
if not self.validate_database_version(self._patroni.get_postgresql_version()):
473+
self.unit.status = BlockedStatus(DIFFERENT_VERSIONS_PSQL_BLOCKING_MESSAGE)
474+
return
475+
469476
if self._update_member_ip():
470477
return
471478

@@ -1577,6 +1584,15 @@ def client_relations(self) -> List[Relation]:
15771584
relations.append(relation)
15781585
return relations
15791586

1587+
def validate_database_version(self, version: str) -> bool:
1588+
peer_db_version = self.app_peer_data.get("database-version")
1589+
1590+
if self.unit.is_leader() and peer_db_version is None:
1591+
self.app_peer_data.update({"database-version": version})
1592+
return True
1593+
1594+
return peer_db_version == self._patroni.get_postgresql_version()
1595+
15801596

15811597
if __name__ == "__main__":
15821598
main(PostgresqlOperatorCharm)

tests/integration/ha_tests/test_self_healing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ async def test_deploy_zero_units(ops_test: OpsTest, charm):
578578
logger.info("connect to DB and create test table")
579579
await create_test_data(connection_string)
580580

581+
# TODO: implement a test using the store with a different version of Postgres
582+
581583
unit_ip_addresses = []
582584
primary_storage = ""
583585
for unit in ops_test.model.applications[app].units:

0 commit comments

Comments
 (0)