Skip to content

Commit

Permalink
Added docstring for upgrade finished hook
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloneppel committed Jul 18, 2023
1 parent afc861b commit 23f91e8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/charms/data_platform_libs/v0/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,29 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None:
raise NotImplementedError

def _on_upgrade_finished(self, event: UpgradeFinishedEvent) -> None:
"""Handler for `upgrade-finished` events."""
"""Handler for `upgrade-finished` events.
K8s only. It should decrement the rolling update strategy partition by using a code
like the following:
from lightkube.core.client import Client
from lightkube.core.exceptions import ApiError
from lightkube.resources.apps_v1 import StatefulSet
partition = self.upgrade_stack[-1]
try:
patch = {"spec": {"updateStrategy": {"rollingUpdate": {"partition": partition}}}}
Client().patch(StatefulSet, name=self.app_name, namespace=self.namespace, obj=patch)
logger.debug(f"Kubernetes StatefulSet partition set to {partition}")
except ApiError as e:
if e.status.code == 403:
logger.error("Kubernetes StatefulSet patch failed: `juju trust` needed")
else:
logger.exception("Kubernetes StatefulSet patch failed")
That shouldn't happen for the last unit (the first that is upgraded). For that unit it
should be done through an action after the upgrade success on that unit is double-checked.
"""
# don't raise if vm substrate, only return
if self.substrate == "vm":
return
Expand Down

0 comments on commit 23f91e8

Please sign in to comment.