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-5481] Ensure that uninitialized variable not referenced in _is_cluster_blocked helper #507

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 11 additions & 2 deletions lib/charms/tempo_k8s/v2/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,20 +811,19 @@ 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()
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 = 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
Expand Down
Loading