[PR] Extended syntax for filtering and accessing labels/annotations/patches/body parts #327
Closed
5 tasks done
Labels
Milestone
What do these changes do?
Extend the resource bodies, body-parts, and patches with properties making them easier to use, and add few handler kwargs for well-known and often-used fields (labels/annotations).
Description
Previously, it was quite common to use complicated Python structures to access the body/patch fields like this:
With this PR, well-known structures are exposed as body/patch properties, and are always behave as "live views" into their original dicts — i.e. every update on the dict is reflected in all views, all updates on the views is reflected in the original dict (similar to how KeysView, ValuesView, ItemsView work in Python itself).
Specifically:
body
kwarg is now always a "live view" to the original RawBody JSON-decoded dict, same as it already was forspec
,meta
,status
kwargs before.labels
&annotations
kwargs are added to all resource-related handlers.body.spec|meta|status
andbody.meta.labels|annotations
are the "live views" to a raw dict, persistent across multiple uses, and are exactly the same objects as provided in the kwargs (i.e. not re-created for every new handler).patch
follows the same.spec|meta|status
semantics with "mutable live views".In addition, the labels/annotations filters are changed to deprecate
None
as an "any value" marker, as it was confusing ("some value is None" does not sound natural). Instead,kopf.PRESENT
orkopf.ABSENT
tokens should be used for labels/annotations filters.Purpose: All of the above adds some conventional features now for the event-driven handlers, but is critically important for the upcoming daemons/timers, where the bodies are updated over time, while the handlers that use these bodies, run in a sequential execution flow (unlike short event handlers).
For the end users, there are no big changes except for the new kwargs and properties available.
Slightly breaking:
body
is now not adict
, but a custom class, therefore it is not JSON-serialisable. Usedict(body)
to make it JSON-serialisable. But there were no expected usage patterns to JSON-serialise the whole body, and here is a quick solution — so, should be fine.Issues/PRs
Type of changes
Checklist
CONTRIBUTORS.txt
The text was updated successfully, but these errors were encountered: