Skip to content

Commit f5b7c8f

Browse files
[DPE-5481] Ensure that uninitialized variable not referenced in _is_cluster_blocked helper (#507)
* Ensure that uninitialized variable not referenced in _is_cluster_blocked helper * Simplify member_state existence in _is_cluster_blocked * Update outdate tracing charm lib
1 parent e7d7efd commit f5b7c8f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/charms/tempo_k8s/v2/tracing.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __init__(self, *args):
107107

108108
# Increment this PATCH version before using `charmcraft publish-lib` or reset
109109
# to 0 if you are raising the major API version
110-
LIBPATCH = 9
110+
LIBPATCH = 10
111111

112112
PYDEPS = ["pydantic"]
113113

@@ -902,7 +902,16 @@ def _get_endpoint(
902902
def get_endpoint(
903903
self, protocol: ReceiverProtocol, relation: Optional[Relation] = None
904904
) -> Optional[str]:
905-
"""Receiver endpoint for the given protocol."""
905+
"""Receiver endpoint for the given protocol.
906+
907+
It could happen that this function gets called before the provider publishes the endpoints.
908+
In such a scenario, if a non-leader unit calls this function, a permission denied exception will be raised due to
909+
restricted access. To prevent this, this function needs to be guarded by the `is_ready` check.
910+
911+
Raises:
912+
ProtocolNotRequestedError:
913+
If the charm unit is the leader unit and attempts to obtain an endpoint for a protocol it did not request.
914+
"""
906915
endpoint = self._get_endpoint(relation or self._relation, protocol=protocol)
907916
if not endpoint:
908917
requested_protocols = set()

src/charm.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,20 +815,19 @@ def _is_cluster_blocked(self) -> bool:
815815
# We need to query member state from the server since member state would
816816
# be 'offline' if pod rescheduled during cluster creation, however
817817
# member-state in the unit peer databag will be 'waiting'
818-
member_state_exists = True
819818
try:
820819
member_state, _ = self._mysql.get_member_state()
821820
except MySQLUnableToGetMemberStateError:
822821
logger.error("Error getting member state while checking if cluster is blocked")
823822
self.unit.status = MaintenanceStatus("Unable to get member state")
824823
return True
825824
except MySQLNoMemberStateError:
826-
member_state_exists = False
825+
member_state = None
827826

828-
if not member_state_exists or member_state == "restarting":
827+
if not member_state or member_state == "restarting":
829828
# avoid changing status while tls is being set up or charm is being initialized
830829
logger.info("Unit is waiting or restarting")
831-
logger.debug(f"{member_state_exists=}, {member_state=}")
830+
logger.debug(f"{member_state=}")
832831
return True
833832

834833
# avoid changing status while async replication is setting up

0 commit comments

Comments
 (0)