From aeb4f433ba276697f69b94642b61d9d27940313a Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Tue, 17 Sep 2024 10:19:47 +0000 Subject: [PATCH 1/3] Ensure that uninitialized variable not referenced in _is_cluster_blocked helper --- src/charm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index d6330924d..f607119a4 100755 --- a/src/charm.py +++ b/src/charm.py @@ -811,15 +811,15 @@ def _is_cluster_blocked(self) -> bool: # We need to query member state from the server since member state would # be 'offline' if pod rescheduled during cluster creation, however # member-state in the unit peer databag will be 'waiting' - member_state_exists = True try: member_state, _ = self._mysql.get_member_state() + member_state_exists = True except MySQLUnableToGetMemberStateError: logger.error("Error getting member state while checking if cluster is blocked") self.unit.status = MaintenanceStatus("Unable to get member state") return True except MySQLNoMemberStateError: - member_state_exists = False + member_state_exists, member_state = False, None if not member_state_exists or member_state == "restarting": # avoid changing status while tls is being set up or charm is being initialized From 97c725b8bebfc036e42d2fc331a78f7524bafe41 Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Tue, 17 Sep 2024 15:42:29 +0000 Subject: [PATCH 2/3] Simplify member_state existence in _is_cluster_blocked --- src/charm.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/charm.py b/src/charm.py index f607119a4..80fe0ff42 100755 --- a/src/charm.py +++ b/src/charm.py @@ -813,18 +813,17 @@ def _is_cluster_blocked(self) -> bool: # member-state in the unit peer databag will be 'waiting' try: member_state, _ = self._mysql.get_member_state() - member_state_exists = True except MySQLUnableToGetMemberStateError: logger.error("Error getting member state while checking if cluster is blocked") self.unit.status = MaintenanceStatus("Unable to get member state") return True except MySQLNoMemberStateError: - member_state_exists, member_state = False, None + member_state = None - if not member_state_exists or member_state == "restarting": + if not member_state or member_state == "restarting": # avoid changing status while tls is being set up or charm is being initialized logger.info("Unit is waiting or restarting") - logger.debug(f"{member_state_exists=}, {member_state=}") + logger.debug(f"{member_state=}") return True # avoid changing status while async replication is setting up From 3e110ab1ae648618a37a2ea78ad5007b4b064341 Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Tue, 17 Sep 2024 15:51:14 +0000 Subject: [PATCH 3/3] Update outdate tracing charm lib --- lib/charms/tempo_k8s/v2/tracing.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/charms/tempo_k8s/v2/tracing.py b/lib/charms/tempo_k8s/v2/tracing.py index d3a7c943e..81bf1f1f5 100644 --- a/lib/charms/tempo_k8s/v2/tracing.py +++ b/lib/charms/tempo_k8s/v2/tracing.py @@ -107,7 +107,7 @@ def __init__(self, *args): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 9 +LIBPATCH = 10 PYDEPS = ["pydantic"] @@ -902,7 +902,16 @@ def _get_endpoint( def get_endpoint( self, protocol: ReceiverProtocol, relation: Optional[Relation] = None ) -> Optional[str]: - """Receiver endpoint for the given protocol.""" + """Receiver endpoint for the given protocol. + + It could happen that this function gets called before the provider publishes the endpoints. + In such a scenario, if a non-leader unit calls this function, a permission denied exception will be raised due to + restricted access. To prevent this, this function needs to be guarded by the `is_ready` check. + + Raises: + ProtocolNotRequestedError: + If the charm unit is the leader unit and attempts to obtain an endpoint for a protocol it did not request. + """ endpoint = self._get_endpoint(relation or self._relation, protocol=protocol) if not endpoint: requested_protocols = set()