From 9e1ccd9fe7c608d09548843fd08bb6d49122bc6e Mon Sep 17 00:00:00 2001 From: Mia Altieri <32723809+MiaAltieri@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:59:42 +0100 Subject: [PATCH] add needed changes to lib (#387) ## Issue missing some necessary changes for mongos running tls ## Solution --- .../mongodb/v0/config_server_interface.py | 20 ++++++------------- lib/charms/mongodb/v0/mongodb_tls.py | 6 ++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/charms/mongodb/v0/config_server_interface.py b/lib/charms/mongodb/v0/config_server_interface.py index c47afc9c7..a8791a1f1 100644 --- a/lib/charms/mongodb/v0/config_server_interface.py +++ b/lib/charms/mongodb/v0/config_server_interface.py @@ -13,7 +13,6 @@ DatabaseProvides, DatabaseRequires, ) -from charms.mongodb.v1.helpers import add_args_to_env, get_mongos_args from charms.mongodb.v1.mongos import MongosConnection from ops.charm import CharmBase, EventBase, RelationBrokenEvent from ops.framework import Object @@ -37,7 +36,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 8 +LIBPATCH = 9 class ClusterProvider(Object): @@ -234,15 +233,15 @@ def _on_relation_changed(self, event) -> None: key_file_contents = self.database_requires.fetch_relation_field( event.relation.id, KEYFILE_KEY ) - config_server_db = self.database_requires.fetch_relation_field( + config_server_db_uri = self.database_requires.fetch_relation_field( event.relation.id, CONFIG_SERVER_DB_KEY ) - if not key_file_contents or not config_server_db: + if not key_file_contents or not config_server_db_uri: self.charm.unit.status = WaitingStatus("Waiting for secrets from config-server") return updated_keyfile = self.update_keyfile(key_file_contents=key_file_contents) - updated_config = self.update_config_server_db(config_server_db=config_server_db) + updated_config = self.update_config_server_db(config_server_db=config_server_db_uri) # avoid restarting mongos when possible if not updated_keyfile and not updated_config and self.is_mongos_running(): @@ -251,7 +250,7 @@ def _on_relation_changed(self, event) -> None: # mongos is not available until it is using new secrets logger.info("Restarting mongos with new secrets") self.charm.unit.status = MaintenanceStatus("starting mongos") - self.charm.restart_mongos_service() + self.charm.restart_charm_services() # restart on high loaded databases can be very slow (e.g. up to 10-20 minutes). if not self.is_mongos_running(): @@ -304,14 +303,7 @@ def update_config_server_db(self, config_server_db) -> bool: if self.charm.config_server_db == config_server_db: return False - mongos_config = self.charm.mongos_config - mongos_start_args = get_mongos_args( - mongos_config, - snap_install=True, - config_server_db=config_server_db, - external_connectivity=self.charm.is_external_client, - ) - add_args_to_env("MONGOS_ARGS", mongos_start_args) + self.charm.update_mongos_args(config_server_db) return True def update_keyfile(self, key_file_contents: str) -> bool: diff --git a/lib/charms/mongodb/v0/mongodb_tls.py b/lib/charms/mongodb/v0/mongodb_tls.py index a26e116be..f64cd4638 100644 --- a/lib/charms/mongodb/v0/mongodb_tls.py +++ b/lib/charms/mongodb/v0/mongodb_tls.py @@ -38,7 +38,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 11 +LIBPATCH = 12 logger = logging.getLogger(__name__) @@ -213,7 +213,9 @@ def _on_certificate_available(self, event: CertificateAvailableEvent) -> None: if not self.charm.is_db_service_ready(): self.charm.unit.status = WaitingStatus("Waiting for MongoDB to start") - elif self.charm.unit.status == WaitingStatus("Waiting for MongoDB to start"): + elif self.charm.unit.status == WaitingStatus( + "Waiting for MongoDB to start" + ) or self.charm.unit.status == MaintenanceStatus("enabling TLS"): # clear waiting status if db service is ready self.charm.unit.status = ActiveStatus()