diff --git a/charms/worker/k8s/src/charm.py b/charms/worker/k8s/src/charm.py index 3f50fc76..d6305487 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -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 @@ -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. diff --git a/charms/worker/k8s/src/token_distributor.py b/charms/worker/k8s/src/token_distributor.py index 367029aa..c476ccb5 100644 --- a/charms/worker/k8s/src/token_distributor.py +++ b/charms/worker/k8s/src/token_distributor.py @@ -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)