Skip to content

Commit

Permalink
Refactor Check Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoflorido committed Nov 13, 2024
1 parent 3948606 commit 022c11d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 4 additions & 8 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ def _get_scrape_jobs(self):
)
def _update_kubernetes_version(self):
"""Update the unit Kubernetes version in the cluster relation."""
relation_name = "cluster"
if not (relation := self.model.get_relation(relation_name)):
if not (relation := self.model.get_relation("cluster")):
assert False, "Missing cluster integration" # nosec
if version := snap_version("k8s"):
relation.data[self.unit]["version"] = version
Expand All @@ -624,24 +623,21 @@ def _announce_kubernetes_version(self):
"""
peer = self.model.get_relation("cluster")
worker = self.model.get_relation("k8s-cluster")
if not all([peer, worker]):
assert False, "Missing cluster integration"

version = snap_version("k8s")
assert version, "k8s-snap is not installed" # nosec

for relation in (peer, worker):
assert relation, "Missing cluster integration" # nosec
units = (unit for unit in relation.units if unit.name != self.unit.name)
for unit in units:
unit_version = relation.data[unit].get("version")
if not unit_version:
assert False, f"Waiting for version from {unit.name}"
assert unit_version, f"Waiting for version from {unit.name}" # nosec
if unit_version != version:
status.add(ops.BlockedStatus(f"Version mismatch with {unit.name}"))
assert False, "Version mismatch with cluster nodes" # nosec
relation.data[self.app]["version"] = version

peer.data[self.app]["version"] = version
worker.data[self.app]["version"] = version

def _get_proxy_env(self) -> Dict[str, str]:
"""Retrieve the Juju model config proxy values.
Expand Down
4 changes: 4 additions & 0 deletions charms/worker/k8s/src/token_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ def _revoke_juju_secret(self, relation: ops.Relation, unit: ops.Unit) -> None:
def active_nodes(self, relation: ops.Relation):
"""Get nodes from application databag for given relation.
This method filters out entries in the application databag that are not
to the cluster units. It uses the regex pattern, which matches patterns
like k8s/0, k8s-worker/0, etc.
Args:
relation (ops.Relation): Which relation (cluster or k8s-cluster)
Expand Down

0 comments on commit 022c11d

Please sign in to comment.