Skip to content

Commit a63da74

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/charm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
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 = "Please select the correct version of postgresql to use. No need to use different versions of postgresql."
9596

9697
Scopes = Literal[APP_SCOPE, UNIT_SCOPE]
9798

@@ -519,6 +520,8 @@ def _on_peer_relation_changed(self, event: HookEvent):
519520

520521
self._update_new_unit_status()
521522

523+
self._validate_database_version()
524+
522525
# Split off into separate function, because of complexity _on_peer_relation_changed
523526
def _start_stop_pgbackrest_service(self, event: HookEvent) -> None:
524527
# Start or stop the pgBackRest TLS server service when TLS certificate change.
@@ -1577,6 +1580,18 @@ def client_relations(self) -> List[Relation]:
15771580
relations.append(relation)
15781581
return relations
15791582

1583+
def _validate_database_version(self):
1584+
"""Checking that only one version of Postgres is used."""
1585+
peer_db_version = self.app_peer_data.get("database-version")
1586+
1587+
if self.unit.is_leader() and peer_db_version is None:
1588+
self.app_peer_data.update({"database-version": self._patroni.get_postgresql_version()})
1589+
return
1590+
1591+
if peer_db_version != self._patroni.get_postgresql_version():
1592+
self.unit.status = BlockedStatus(DIFFERENT_VERSIONS_PSQL_BLOCKING_MESSAGE)
1593+
return
1594+
15801595

15811596
if __name__ == "__main__":
15821597
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)