Skip to content

Commit

Permalink
add needed changes to lib (#387)
Browse files Browse the repository at this point in the history
## Issue
missing some necessary changes for mongos running tls 

## Solution
  • Loading branch information
MiaAltieri authored Mar 25, 2024
1 parent 93b8f11 commit 9e1ccd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 6 additions & 14 deletions lib/charms/mongodb/v0/config_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions lib/charms/mongodb/v0/mongodb_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 9e1ccd9

Please sign in to comment.