kopf icon indicating copy to clipboard operation
kopf copied to clipboard

What is the recommended way to perform resource rollbacks?

Open tomach opened this issue 2 years ago • 0 comments

Keywords

rollback restore

Problem

Is there a way to properly restore the old object state for @kopf.on.update or @kopf.on.field handlers in case there is a kopf.HandlerTimeoutError or kopf.PermanentError raised in a (sub-)handler?

e.g. in our case we use kopf in an operator handling a CRD

@kopf.on.field(
    "my_api_group",
    "v1",
    "my_resource",
    field="spec.myfield",
)
async def my_on_field(
    namespace: str,
    name: str,
    old: str,
    new: str,
    patch: kopf.Patch,
    **kwargs,
):
    ...
    # perform rollback manually somewhere in custom error handling at the end of the execution
    patch.setdefault("spec", {})["myfield"] = old

results in an infinite loop trying to set the value back and forth.

Or when done in subhandlers, kopf stops execution as soon as the old resource value is restored and matches what is stored in the last-handled-configuration annotation. In this case also the subhandler's status annotations remain in the resource leaving it in an unfinished state.

Thanks!

tomach avatar Feb 28 '23 07:02 tomach