diff --git a/lib/charms/mongodb/v0/config_server_interface.py b/lib/charms/mongodb/v0/config_server_interface.py index 5392367d0..44e485bbb 100644 --- a/lib/charms/mongodb/v0/config_server_interface.py +++ b/lib/charms/mongodb/v0/config_server_interface.py @@ -58,9 +58,13 @@ class ClusterProvider(Object): """Manage relations between the config server and mongos router on the config-server side.""" def __init__( - self, charm: CharmBase, relation_name: str = Config.Relations.CLUSTER_RELATIONS_NAME + self, + charm: CharmBase, + relation_name: str = Config.Relations.CLUSTER_RELATIONS_NAME, + substrate: str = Config.Substrate.VM, ) -> None: """Constructor for ShardingProvider object.""" + self.substrate = substrate self.relation_name = relation_name self.charm = charm self.database_provides = DatabaseProvides(self.charm, relation_name=self.relation_name) @@ -395,16 +399,14 @@ def handle_mongos_k8s_users_removal(self) -> None: Raises: PyMongoError """ - if ( - self.charm.unit.is_leader() - and self.charm.client_relations.remove_all_relational_users() - and self.substrate == Config.Substrate.K8S - ): - self.charm.client_relations.remove_all_relational_users() - - # now that the client mongos users have been removed we can remove ourself - with MongoConnection(self.charm.mongo_config) as mongo: - mongo.drop_user(self.charm.mongo_config.username) + if not self.charm.unit.is_leader() or self.substrate != Config.Substrate.K8S: + return + + self.charm.client_relations.remove_all_relational_users() + + # now that the client mongos users have been removed we can remove ourself + with MongoConnection(self.charm.mongo_config) as mongo: + mongo.drop_user(self.charm.mongo_config.username) def pass_hook_checks(self, event): """Runs the pre-hooks checks for ClusterRequirer, returns True if all pass."""