def deliver_results( *, outcomes: Mapping[ids.HandlerId, execution.Outcome], patch: patches.Patch, ) -> None: """ Store the results (as returned from the handlers) to the resource. This is not the handlers' state persistence, but the results' persistence. First, the state persistence is stored under ``.status.kopf.progress``, and can (later) be configured to be stored in different fields for different operators operating the same objects: ``.status.kopf.{somename}.progress``. The handlers' result are stored in the top-level ``.status``. Second, the handler results can (also later) be delivered to other objects, e.g. to their owners or label-selected related objects. For this, another class/module will be added. For now, we keep state- and result persistence in one module, but separated. """ for handler_id, outcome in outcomes.items(): if outcome.exception is not None: pass elif outcome.result is None: pass elif isinstance(outcome.result, collections.abc.Mapping): # TODO: merge recursively (patch-merge), do not overwrite the keys if they are present. patch.setdefault('status', {}).setdefault(handler_id, {}).update(outcome.result) else: patch.setdefault('status', {})[handler_id] = copy.deepcopy(outcome.result)
def block_deletion( *, body: bodies.Body, patch: patches.Patch, finalizer: str, ) -> None: if not is_deletion_blocked(body=body, finalizer=finalizer): finalizers = body.get('metadata', {}).get('finalizers', []) patch.setdefault('metadata', {}).setdefault('finalizers', list(finalizers)) patch['metadata']['finalizers'].append(finalizer)
def allow_deletion( *, body: bodies.Body, patch: patches.Patch, finalizer: str, ) -> None: if is_deletion_blocked(body=body, finalizer=finalizer): finalizers = body.get('metadata', {}).get('finalizers', []) patch.setdefault('metadata', {}).setdefault('finalizers', list(finalizers)) if finalizer in patch['metadata']['finalizers']: patch['metadata']['finalizers'].remove(finalizer)