How to use the kopf.on.resume function in kopf

To help you get started, we’ve selected a few kopf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zalando-incubator / kopf / tests / registries / test_decorators.py View on Github external
    @kopf.on.resume('group', 'version', 'plural',
                    id='id', registry=registry,
                    errors=ErrorsMode.PERMANENT, timeout=123, retries=456, backoff=78,
                    deleted=True,
                    labels={'somelabel': 'somevalue'},
                    annotations={'someanno': 'somevalue'})
    def fn(**_):
        pass
github zalando-incubator / kopf / tests / registries / test_decorators.py View on Github external
    @kopf.on.resume('group', 'version', 'plural')
    def fn(**_):
        pass
github zalando-incubator / kopf / examples / 05-handlers / example.py View on Github external
@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
def resume_fn_2(cause, **kwargs):
    print(f'RESUMED 2nd')
github IntelAI / nauta / applications / experiment-operator / nauta_operator.py View on Github external
@kopf.on.resume('aipg.intel.com', 'v1', 'runs')
async def handle_run_on_resume(namespace, name, logger, spec, **kwargs):
    try:
        run_state = RunStatus(spec['state'])
    except ValueError:
        raise kopf.PermanentError(f'Run {name} is invalid - cannot infer status from spec: {spec}')

    if run_state in {RunStatus.COMPLETE, RunStatus.FAILED, RunStatus.CANCELLED}:
        logger.info(f'Run {name} already in final state: {run_state.value}.')
        if namespace in tasks and name in tasks[namespace]:
            del tasks[namespace][name]
        return
    elif not tasks.get(namespace, {}).get(name):
        logger.info(f'Resuming monitoring task for run {name}.')
        task = asyncio.create_task(monitor_run(namespace, name, logger))
        tasks.setdefault(namespace, {})
        tasks[namespace][name] = task
github elemental-lf / benji / src / benji / k8s_operator / crd / restore.py View on Github external
@kopf.on.resume(*BenjiRestore.group_version_plural())
@kopf.on.create(*BenjiRestore.group_version_plural())
def benji_restore(namespace: str, spec: Dict[str, Any], status: Dict[str, Any], body: Dict[str, Any], logger,
                  **_) -> Optional[Dict[str, Any]]:
    if RESOURCE_STATUS_CHILDREN in status:
        # We've already seen this resource
        return

    pvc_name = spec[K8S_RESTORE_SPEC_PERSISTENT_VOLUME_CLAIM_NAME]
    version_name = spec[K8S_RESTORE_SPEC_VERSION_NAME]
    storage_class_name = spec[K8S_RESTORE_SPEC_STORAGE_CLASS_NAME]
    overwrite = spec.get(K8S_RESTORE_SPEC_OVERWRITE, False)

    benji = APIClient()
    check_version_access(benji, version_name, body)

    command = [
github redhat-cop / anarchy / operator / operator.py View on Github external
@kopf.on.resume(runtime.operator_domain, runtime.api_version, 'anarchyactions', labels={runtime.run_label: kopf.ABSENT})
@kopf.on.update(runtime.operator_domain, runtime.api_version, 'anarchyactions', labels={runtime.run_label: kopf.ABSENT})
def handle_action_activity(body, logger, **_):
    action = AnarchyAction(body)
    if not action.has_owner:
        action.set_owner(runtime)
    elif not action.has_started:
        if action.after_datetime <= datetime.utcnow():
            action.start(runtime)
        else:
            AnarchyAction.cache_put(action)
github elemental-lf / benji / src / benji / k8s_operator / crd / retention_schedule.py View on Github external
@kopf.on.resume(*ClusterBenjiRetentionSchedule.group_version_plural())
@kopf.on.create(*ClusterBenjiRetentionSchedule.group_version_plural())
@kopf.on.update(*ClusterBenjiRetentionSchedule.group_version_plural())
def benji_retention_schedule(namespace: str, spec: Dict[str, Any], body: Dict[str, Any], logger,
                             **_) -> Optional[Dict[str, Any]]:
    schedule = spec[K8S_RESTORE_SPEC_SCHEDULE]
    retention_rule = spec[K8S_RESTORE_SPEC_RETENTION_RULE]

    instance_filter = f'labels["{LABEL_INSTANCE}"] == "{benji_instance}"'
    match_versions = spec.get(K8S_RESTORE_SPEC_MATCH_VERSIONS, None)
    if match_versions is not None:
        match_versions = f'({match_versions}) and {instance_filter}'
    else:
        match_versions = instance_filter

    if body['kind'] == BenjiRetentionSchedule.kind:
        match_versions = f'{match_versions} and labels["{LABEL_K8S_PVC_NAMESPACE}"] == "{namespace}"'
github zalando-incubator / kopf / examples / 05-handlers / example.py View on Github external
@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
def resume_fn_1(cause, **kwargs):
    print(f'RESUMED 1st')
github elemental-lf / benji / src / benji / k8s_operator / crd / backup_schedule.py View on Github external
@kopf.on.resume('batch', 'v1', 'jobs', labels={LABEL_PARENT_KIND: CRD_CLUSTER_BACKUP_SCHEDULE.name})
@kopf.on.delete('batch', 'v1', 'jobs', labels={LABEL_PARENT_KIND: CRD_CLUSTER_BACKUP_SCHEDULE.name})
@kopf.on.field('batch', 'v1', 'jobs', field='status', labels={LABEL_PARENT_KIND: CRD_CLUSTER_BACKUP_SCHEDULE.name})
def benji_track_job_status_cluster_backup_schedule(**_) -> Optional[Dict[str, Any]]:
    return track_job_status(crd=CRD_CLUSTER_BACKUP_SCHEDULE, **_)
github elemental-lf / benji / src / benji / k8s_operator / crd / backup_schedule.py View on Github external
@kopf.on.resume('batch', 'v1', 'jobs', labels={LABEL_PARENT_KIND: CRD_BACKUP_SCHEDULE.name})
@kopf.on.delete('batch', 'v1', 'jobs', labels={LABEL_PARENT_KIND: CRD_BACKUP_SCHEDULE.name})
@kopf.on.field('batch', 'v1', 'jobs', field='status', labels={LABEL_PARENT_KIND: CRD_BACKUP_SCHEDULE.name})
def benji_track_job_status_backup_schedule(**_) -> Optional[Dict[str, Any]]:
    return track_job_status(crd=CRD_BACKUP_SCHEDULE, **_)