-
Notifications
You must be signed in to change notification settings - Fork 87
Daemons & timers for background processing and reconciliation #330
Conversation
🤖 zincr found 0 problems , 1 warning
Details on how to resolve are provided below Large CommitsChecks all commits for large additions to a single file. Large commits should be reviewed more carefully for potential copyright and licensing issues This file contains a substantial change, please review to determine if the change comes from an external source and if there are any copyright or licensing issues to be aware of
|
This pull request introduces 2 alerts when merging 6505cb4 into de23abe - view on LGTM.com new alerts:
|
6505cb4
to
34f32e7
Compare
34f32e7
to
bf1f081
Compare
In the assumption that new handler types are coming (daemons, timers), and they must be rendered differently, not as just "handlers", while using the same invocation routines.
The real sleep is needed in some cases to give control to asyncio's event loop (`sleep(0)`), or to debug the tests. When it is mocked, it is difficult to do anything. All the code uses the sleeping engine now, so there is no need to check for the actual `asyncio.sleep()` calls.
bf1f081
to
2eb91dc
Compare
The tests are rudimentary, only for the smoke-testing of daemons & timers. This PR took already too much time, and is too big. The low-level primitives are tested indirectly through the existing tests, and manually by running examples with Minikube (including the examples 14 & 15 for daemons & timers). The framework itself will be tested for backward compatibility by deployed a release candidate to our own clusters and utilising the new features (incl. daemons & timers). More detailed tests for all little aspects will be added later as separate PRs — with lower priority (time-wise). |
0afb22e
to
75e227f
Compare
assert dummy.mock.call_count == 1 | ||
assert k8s_mocked.patch_obj.call_count == 0 | ||
assert k8s_mocked.sleep_or_wait.call_count == 1 # one for each retry | ||
assert k8s_mocked.sleep_or_wait.call_args_list[0][0][0] is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not readable. Maybe from unittest.mock import call
and
assert ...call_args_list == [call(*args, **kwargs)]
is better. Applies to the other stuff also. In the current situation, there might be obscure out of index exceptions if the test breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking the test in that case is intended. The first index is "secured" by a preceding check for the number of calls.
But you are right, making tests more readable is a good idea — but should be done for all the tests. Now, the tests in overall are in a clumsy state, grown over the year, and they were never refactored. Some of them are duplicating each other, some aspects of the code are just missing.
I've created #338 to collect the ideas on the tests, and added this one there.
What do these changes do?
Add background daemons & timers for resources.
Description
Previously, the handlers were event-driven — i.e. when something changes on the resource. If nothing changes, no handlers are called. To have reconciliation or other activities happening during the lifetime of a resource, the developers had to do their own task/thread orchestration.
With this PR, the task/thread orchestration is generalised to a new framework feature to perform background reconciliation with external systems, locally managed applications, or even local children K8s resources not the event-driven way:
The daemons run as long as the resource exists. They are stopped/cancelled when the resource is deleted (or when the operator exits/restarts). The daemons can be automatically restarted or left dead if exited (
restart_backoff
).The timers are also triggered as long as the resource exists, but by schedule. They can be postponed by few seconds since the last change (
idle
), or since the resource creation / operator startup (initial_backoff
), can have sharp or soft intervals (see the docs), etc.For more examples & options, see
/examples/
folder and the doc updates in this PR/branch.Issues/PRs
Type of changes
Checklist
CONTRIBUTORS.txt
WARNING: This PR is a preview. It is runnable and usable, but few minor things are not finished yet:
stopper
synchronization primitive.DaemonStopperReason
).