|
92 | 92 |
|
93 | 93 | PRIMARY_NOT_REACHABLE_MESSAGE = "waiting for primary to be reachable from this unit"
|
94 | 94 | 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." |
95 | 96 |
|
96 | 97 | Scopes = Literal[APP_SCOPE, UNIT_SCOPE]
|
97 | 98 |
|
@@ -519,6 +520,8 @@ def _on_peer_relation_changed(self, event: HookEvent):
|
519 | 520 |
|
520 | 521 | self._update_new_unit_status()
|
521 | 522 |
|
| 523 | + self._validate_database_version() |
| 524 | + |
522 | 525 | # Split off into separate function, because of complexity _on_peer_relation_changed
|
523 | 526 | def _start_stop_pgbackrest_service(self, event: HookEvent) -> None:
|
524 | 527 | # Start or stop the pgBackRest TLS server service when TLS certificate change.
|
@@ -1577,6 +1580,18 @@ def client_relations(self) -> List[Relation]:
|
1577 | 1580 | relations.append(relation)
|
1578 | 1581 | return relations
|
1579 | 1582 |
|
| 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 | + |
1580 | 1595 |
|
1581 | 1596 | if __name__ == "__main__":
|
1582 | 1597 | main(PostgresqlOperatorCharm)
|
0 commit comments