From ea401214cbe491018bad04a8cf55dfd2bbf459ea Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Tue, 16 Jul 2024 14:18:18 +0300 Subject: [PATCH] Repatch service --- src/relations/backend_database.py | 9 +++++---- src/upgrade.py | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/relations/backend_database.py b/src/relations/backend_database.py index 426fb178a..b0e6988eb 100644 --- a/src/relations/backend_database.py +++ b/src/relations/backend_database.py @@ -344,10 +344,11 @@ def _on_relation_departed(self, event: RelationDepartedEvent): if event.departing_unit == self.charm.unit: # This should only occur when the relation is being removed, not on scale-down - self.charm.peers.unit_databag.update({ - f"{BACKEND_RELATION_NAME}_{event.relation.id}_departing": "true" - }) - logger.warning("added relation-departing flag to peer databag") + if self.charm.peers.unit_databag: + self.charm.peers.unit_databag.update({ + f"{BACKEND_RELATION_NAME}_{event.relation.id}_departing": "true" + }) + logger.warning("added relation-departing flag to peer databag") return if not self.charm.unit.is_leader() or event.departing_unit.app != self.charm.app: diff --git a/src/upgrade.py b/src/upgrade.py index 9d24f15a5..2cc2b1dce 100644 --- a/src/upgrade.py +++ b/src/upgrade.py @@ -20,6 +20,8 @@ from pydantic import BaseModel from typing_extensions import override +from constants import CLIENT_RELATION_NAME + DEFAULT_MESSAGE = "Pre-upgrade check failed and cannot safely upgrade" logger = logging.getLogger(__name__) @@ -89,6 +91,11 @@ def _on_pgbouncer_pebble_ready(self, event: WorkloadEvent) -> None: if self.peer_relation.data[self.charm.unit].get("state") != "upgrading": return + if self.charm.unit.is_leader(): + self.charm.patch_port(self.charm.client_relation.external_connectivity()) + for relation in self.model.relations.get(CLIENT_RELATION_NAME, []): + self.client_relation.update_connection_info(relation) + try: self._cluster_checks() except ClusterNotReadyError: