Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR] Use memo for arbitrary per-resource payload during operator lifetime #234

Closed
2 tasks
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Closed
2 tasks
Labels
archive enhancement New feature or request

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

A pull request by nolar at 2019-11-14 12:48:12+00:00
Original URL: zalando-incubator/kopf#234
Merged by nolar at 2019-11-14 13:47:59+00:00

Issue : #112

Description

Since the per-resource in-memory runtime-only containers are already present in the core for internal purposes, it is easy to expose memo kwarg to the handlers, so that the can store arbitrary information or objects about resources.

Same as for the internal use, this should be the objects that are scoped to the operator life time, fully lost on restarts, i.e. not persistent. E.g. threads, tasks, locks, events. Maybe some regular scalars, if their meaning is also scoped to the operator process.

Example:

import kopf

@kopf.on.create('zalando.org', 'v1', 'kopfexamples', cooldown=10)
def create_fn_1(memo, **kwargs):
    print(f'{memo.xyz}')

@kopf.on.create('zalando.org', 'v1', 'kopfexamples')
def create_fn_2(memo, **kwargs):
    memo.xyz = 100

In this example, create_fn_1 raises AttributeError on the 1st attempt, then goes to create_fn_2, and then retries create_fn_1 in 10 seconds with the .xyz field already set.

Both dictionary and object interfaces are supported.

The documentation is intentionally limited — let's first see how it will be used, and what can be the examples.

Types of Changes

  • New feature (non-breaking change which adds functionality)

Review

List of tasks the reviewer must do to review the PR

  • Tests
  • Documentation
@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] [PR] Use memo for arbitrary per-resource payload during operator lifetime Aug 19, 2020
@kopf-archiver kopf-archiver bot added the enhancement New feature or request label Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

0 participants