From 0f10e56f0f52d30cf8a564dbd352edb5f9a37bf3 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 17 Apr 2024 14:02:01 +0000 Subject: [PATCH] Exclude opensearch lock index from restore (#233) https://github.com/canonical/opensearch-operator/pull/211#pullrequestreview-1974926815 --- lib/charms/opensearch/v0/opensearch_backups.py | 7 ++++++- lib/charms/opensearch/v0/opensearch_locking.py | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_backups.py b/lib/charms/opensearch/v0/opensearch_backups.py index ad3275da8..68ce8e91f 100644 --- a/lib/charms/opensearch/v0/opensearch_backups.py +++ b/lib/charms/opensearch/v0/opensearch_backups.py @@ -66,6 +66,7 @@ def __init__(...): OpenSearchHttpError, OpenSearchNotFullyReadyError, ) +from charms.opensearch.v0.opensearch_locking import OpenSearchNodeLock from charms.opensearch.v0.opensearch_plugins import OpenSearchBackupPlugin, PluginState from ops.charm import ActionEvent from ops.framework import EventBase, Object @@ -92,7 +93,11 @@ def __init__(...): S3_REPO_BASE_PATH = "/" -INDICES_TO_EXCLUDE_AT_RESTORE = {".opendistro_security", ".opensearch-observability"} +INDICES_TO_EXCLUDE_AT_RESTORE = { + ".opendistro_security", + ".opensearch-observability", + OpenSearchNodeLock.OPENSEARCH_INDEX, +} REPO_NOT_CREATED_ERR = "repository type [s3] does not exist" REPO_NOT_ACCESS_ERR = f"[{S3_REPOSITORY}] path [{S3_REPO_BASE_PATH}] is not accessible" diff --git a/lib/charms/opensearch/v0/opensearch_locking.py b/lib/charms/opensearch/v0/opensearch_locking.py index 4b92a7ccb..36b54ef5b 100644 --- a/lib/charms/opensearch/v0/opensearch_locking.py +++ b/lib/charms/opensearch/v0/opensearch_locking.py @@ -185,7 +185,7 @@ class OpenSearchNodeLock(ops.Object): Uses OpenSearch document for lock. Falls back to peer databag if no units online """ - _OPENSEARCH_INDEX = ".charm_node_lock" + OPENSEARCH_INDEX = ".charm_node_lock" def __init__(self, charm: "opensearch_base_charm.OpenSearchBaseCharm"): super().__init__(charm, "opensearch-node-lock") @@ -198,7 +198,7 @@ def _unit_with_lock(self, host) -> str | None: try: document_data = self._opensearch.request( "GET", - endpoint=f"/{self._OPENSEARCH_INDEX}/_source/0", + endpoint=f"/{self.OPENSEARCH_INDEX}/_source/0", host=host, alt_hosts=self._charm.alt_hosts, retries=3, @@ -242,7 +242,7 @@ def acquired(self) -> bool: # noqa: C901 try: self._opensearch.request( "PUT", - endpoint=f"/{self._OPENSEARCH_INDEX}", + endpoint=f"/{self.OPENSEARCH_INDEX}", host=host, alt_hosts=alt_hosts, retries=3, @@ -263,7 +263,7 @@ def acquired(self) -> bool: # noqa: C901 try: self._opensearch.request( "PUT", - endpoint=f"/{self._OPENSEARCH_INDEX}/_create/0?refresh=true", + endpoint=f"/{self.OPENSEARCH_INDEX}/_create/0?refresh=true", host=host, alt_hosts=alt_hosts, retries=3, @@ -330,7 +330,7 @@ def release(self): try: self._opensearch.request( "DELETE", - endpoint=f"/{self._OPENSEARCH_INDEX}/_doc/0?refresh=true", + endpoint=f"/{self.OPENSEARCH_INDEX}/_doc/0?refresh=true", host=host, alt_hosts=alt_hosts, retries=3,