Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

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

Closed
nolar opened this issue May 10, 2019 · 0 comments · Fixed by #105
Closed

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

nolar opened this issue May 10, 2019 · 0 comments · Fixed by #105
Assignees
Labels
enhancement New feature or request

Comments

@nolar
Copy link
Contributor

nolar commented May 10, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant