Skip to content

Commit 4fb533b

Browse files
Handle upgrade of top of the stack Juju leader (#492)
Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent fed95f2 commit 4fb533b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/charms/data_platform_libs/v0/upgrade.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def restart(self, event) -> None:
285285

286286
# Increment this PATCH version before using `charmcraft publish-lib` or reset
287287
# to 0 if you are raising the major API version
288-
LIBPATCH = 16
288+
LIBPATCH = 17
289289

290290
PYDEPS = ["pydantic>=1.10,<2", "poetry-core"]
291291

@@ -907,6 +907,17 @@ def _on_upgrade_charm(self, event: UpgradeCharmEvent) -> None:
907907
logger.error(e)
908908
self.set_unit_failed()
909909
return
910+
top_unit_id = self.upgrade_stack[-1]
911+
top_unit = self.charm.model.get_unit(f"{self.charm.app.name}/{top_unit_id}")
912+
if (
913+
top_unit == self.charm.unit
914+
and self.peer_relation.data[self.charm.unit].get("state") == "recovery"
915+
):
916+
# While in a rollback and the Juju leader unit is the top unit in the upgrade stack, emit the event
917+
# for this unit to start the rollback.
918+
self.peer_relation.data[self.charm.unit].update({"state": "ready"})
919+
self.on_upgrade_changed(event)
920+
return
910921
self.charm.unit.status = WaitingStatus("other units upgrading first...")
911922
self.peer_relation.data[self.charm.unit].update({"state": "ready"})
912923

0 commit comments

Comments
 (0)