Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-5235] add changes necessary for mongos-k8s ext connections #483

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/charms/mongodb/v1/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pymongo.errors import PyMongoError

from config import Config
from exceptions import FailedToGetHostsError

# The unique Charmhub library identifier, never change it
LIBID = "4067879ef7dd4261bf6c164bc29d94b1"
Expand All @@ -31,7 +32,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 12
LIBPATCH = 13

logger = logging.getLogger(__name__)
REL_NAME = "database"
Expand Down Expand Up @@ -145,7 +146,11 @@ def _on_relation_event(self, event):

try:
self.oversee_users(departed_relation_id, event)
except PyMongoError as e:
except (PyMongoError, FailedToGetHostsError) as e:
# Failed to get hosts error is unique to mongos-k8s charm. In other charms we do not
# foresee issues to retrieve hosts. However in external mongos-k8s, the leader can
# attempt to retrieve hosts while non-leader units are still enabling node port
# resulting in an exception.
logger.error("Deferring _on_relation_event since: error=%r", e)
event.defer()
return
Expand Down
4 changes: 4 additions & 0 deletions src/exceptions.py
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ class SecretAlreadyExistsError(MongoSecretError):

class NotConfigServerError(Exception):
"""Raised when an operation is performed on a component that is not a config server."""


class FailedToGetHostsError(Exception):
"""Raised when charm fails to retrieve hosts."""
Loading