Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@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
@kopf.on.resume('group', 'version', 'plural')
def fn(**_):
pass
@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
def resume_fn_2(cause, **kwargs):
print(f'RESUMED 2nd')
@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
@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 = [
@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)
@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}"'
@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
def resume_fn_1(cause, **kwargs):
print(f'RESUMED 1st')
@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, **_)
@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, **_)