-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Keep a live in-memory "view" of all matching resources in the cluster #661
Conversation
This comment has been minimized.
This comment has been minimized.
8642449
to
8fbadd3
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
68035e1
to
c9df0f0
Compare
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
Signed-off-by: Sergey Vasilyev <[email protected]>
If the resource is non-indexable, there is no need to create the individual toggles neither for the resource kind nor for each individual resource object — such resources do not block the operator's readiness (but can be blocked themselves). In practice, even if created, those toggles will be turned on and/or dropped as soon as the processing routine is entered and finds that there are no indexing handlers (nothing to do). This is a waste of computing power and memory on startup, which can affect the operators in massive clusters — for no benefit. Instead, only create resource kind's & resource object's toggles when and if there are indexing handlers to be executed. As a particular case, when an operator has no indices at all (assumed to be the default and the most common case), create no single toggle, or at most one (for the global operator block until all specialised per-resource-kind blockers are checked & skipped). Without this fix, there will be as many useless toggles as there are resource kinds (usually below ten) PLUS resource objects (can be in hundreds or thousands). Signed-off-by: Sergey Vasilyev <[email protected]>
So far, I gave it a couple of days to settle down and check if there are any other after-thoughts. There are none. It can be merged. The only concern left is that it could be beneficial in the future if other builtin types are specially interpreted similar to the 1st-level In that case, it would require backward-incompatible changes (now, such values are treated as values). One solution would be to wrap these types now in something like I believe, this forward compatibility cannot be ensured now. This can be extended later with additional options to |
Indexers automatically maintain in-memory overviews of resources (indices), grouped by keys that are usually calculated based on these resources.
See the detailed description and several recipes in the .rst file in the PR's changes. The essence:
The indices can be used for cross-resource awareness: e.g., when a resource of kind X is changed, it can get all the information about all resources of kind Y without talking to the Kubernetes API.
The indices are optimized for lookups by keys (O(1) — the same as Python's dicts), though iterating over them is also an option. The updates & deletions are O(k), where "k" is the number of keys per object (not of the overall keys!).
A side-note: The in-memory indices are a step further towards cross-resource handlers (an example: when a child pod is changed, the cross-resource handler should be invoked in the context of its parent, not of the child itself, with all other pods' information at hand). In that case, only one resource is known due to the arrived event, while another resource should be either remembered in-memory or fake-patched with the full info of each child to trigger the handling. The latter way looks stressful to K8s & K8s API, so the in-memory way seems the only viable solution.
Things left to do (can take time):
key=
callback or the key structure must be frozen (mapping to K8s API uniqueness: resource, namespace, name). What if 2+ handlers for the same function have different key structures?(namespace, name)
key is enough. Resources are not needed as a part of the key, as they can be replaced by a cache name/id.ttl
.defaultdict
. Separate read-only (operator) and read-write (framework) modes accessors.