From a40251086e408ee9fc09141bd1847182e5b34213 Mon Sep 17 00:00:00 2001 From: phvalguima Date: Mon, 6 May 2024 14:22:41 +0200 Subject: [PATCH] Fix backup status on non-leader units (#298) ## Issue: The backup module sets application status on non-leader units, which causes an exception as a non allowed operation. --- lib/charms/opensearch/v0/opensearch_backups.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_backups.py b/lib/charms/opensearch/v0/opensearch_backups.py index 602760527..6bc189dd9 100644 --- a/lib/charms/opensearch/v0/opensearch_backups.py +++ b/lib/charms/opensearch/v0/opensearch_backups.py @@ -294,14 +294,16 @@ def _on_peer_relation_changed(self, event) -> None: def _on_s3_relation_event(self, event: EventBase) -> None: """Processes the non-orchestrator cluster events.""" - self.charm.status.set(BlockedStatus(S3RelShouldNotExist), app=True) + if self.charm.unit.is_leader(): + self.charm.status.set(BlockedStatus(S3RelShouldNotExist), app=True) logger.info("Non-orchestrator cluster, abandon s3 relation event") return def _on_s3_relation_broken(self, event: EventBase) -> None: """Processes the non-orchestrator cluster events.""" self.charm.status.clear(S3RelMissing) - self.charm.status.clear(S3RelShouldNotExist, app=True) + if self.charm.unit.is_leader(): + self.charm.status.clear(S3RelShouldNotExist, app=True) logger.info("Non-orchestrator cluster, abandon s3 relation event") return @@ -738,10 +740,12 @@ def apply_api_config_if_needed(self) -> None: # (3) based on the response, set the message status if state != BackupServiceState.SUCCESS: logger.error(f"Failed to setup backup service with state {state}") - self.charm.status.set(BlockedStatus(BackupSetupFailed), app=True) + if self.charm.unit.is_leader(): + self.charm.status.set(BlockedStatus(BackupSetupFailed), app=True) self.charm.status.clear(BackupConfigureStart) return - self.charm.status.clear(BackupSetupFailed, app=True) + if self.charm.unit.is_leader(): + self.charm.status.clear(BackupSetupFailed, app=True) self.charm.status.clear(BackupConfigureStart) def _on_s3_created(self, _):