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

Enhance Upgrade Status #216

Merged
merged 6 commits into from
Dec 13, 2024
Merged
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
34 changes: 28 additions & 6 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,23 +729,45 @@ def _announce_kubernetes_version(self):
if not local_version:
raise ReconcilerError("k8s-snap is not installed")

peer = self.model.get_relation(CLUSTER_RELATION)
worker = self.model.get_relation(CLUSTER_WORKER_RELATION)
relation_config = {
"peer": self.model.get_relation(CLUSTER_RELATION),
"worker": self.model.get_relation(CLUSTER_WORKER_RELATION),
}

waiting_units = {role: 0 for role in relation_config}

for relation in (peer, worker):
for role, relation in relation_config.items():
if not relation:
continue

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:
raise ReconcilerError(f"Waiting for version from {unit.name}")
if unit_version != local_version:
# NOTE: Add a check to validate if we are doing an upgrade
status.add(ops.WaitingStatus("Upgrading the cluster"))
return
waiting_units[role] += 1

relation.data[self.app]["version"] = local_version

if not any(waiting_units.values()):
return

role_names = {
"peer": "Control Plane",
"worker": "Worker",
}

waiting_parts = [
f"{count} {role_names[role]}{'s' if count > 1 else ''}"
for role, count in waiting_units.items()
if count
]

status_msg = f"Waiting for {', '.join(waiting_parts)} to upgrade"
status.add(ops.WaitingStatus(status_msg))
raise ReconcilerError(status_msg)

def _get_proxy_env(self) -> Dict[str, str]:
"""Retrieve the Juju model config proxy values.

Expand Down
Loading