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

Handler for starting the per-object background threads/coroutines #60

Closed
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Closed

Handler for starting the per-object background threads/coroutines #60

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

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

An issue by nolar at 2019-05-10 15:23:25+00:00
Original URL: zalando-incubator/kopf#60
 

In some case, it is desired to have a background thread or async coroutine for every object existing in the cluster (if the operator developer decides so).

Example use-case: polling the external services & APIs when the custom resource represents the jobs of an external system with its status field.

It can be done from the @kopf.on.create() handler. However, when the operator restarts, and there are no events on the object, no handler will ever be called, meaning the operator will not react to the external state changes.

With this handler, the problem can be solved:

import kopf

@kopf.on.seen('zalando.org', 'v1', 'kopfexamples')
def seen_fn(meta, **_):
    thread = threading.Thread(target=monitoring_fn, args=(meta['name'],))
    thread.start()

Other names: @kopf.on.regain(), @kopf.on.restore().


UNDECIDED:

Option A:

The handler must be called only in the case when the operator restarts, gets a fresh list of the objects as part of the watch request, and notices there are some object already handled.

It must NOT be called when:

  • When the object is actually created while the operator is running ("first seen" or "create" causes).
  • When the operator starts and gets a fresh list of the objects as part of the watch request, and the objects are new and the @kopf.on.create handler should be called.

Options B:

  • When the object is fully handled (including the creation), and now needs the monitoring — both in cases of creation, and the operator restart.

@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] Handler for starting the per-object background threads/coroutines 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