Add SharedInformer implementation to python-client#2515
Add SharedInformer implementation to python-client#2515k8s-ci-robot merged 14 commits intomasterfrom
Conversation
…example Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
@copilot can you add support for BOOKMARK events? |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in 9c708ad. Added a |
|
@copilot can you implement it so that the most recent resourceVersion is stored and used for the re-list operation? |
… on 410 Gone Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in d21aa1b. |
|
@copilot can you add end-to-end tests against a real cluster |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in 63bd3d5. Added
Each test uses a unique name (UUID suffix) and registers |
The PR description has been updated in 1d10150 with a properly-formatted standalone
Done in 1d10150. Copyright year updated to 2026 in all 6 new files (existing files untouched). Added |
| elif evt_type == BOOKMARK: | ||
| # BOOKMARK events carry an updated resource version but | ||
| # no object state change; the Watch instance already | ||
| # records the new resource_version internally. |
There was a problem hiding this comment.
Watch added the support for BOOKMARK event handling a couple of months ago in #2505, wondering if copilot could add a test for BOOKMARK ?
|
/lgtm I'll leave it to @roycaihw to further review and approve |
|
@brendandburns what is your initial / first prompt to copilot that created this PR? |
|
@copilot please add unit tests for BOOKMARK events. |
…kmarks Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> Agent-Logs-Url: https://github.com/kubernetes-client/python/sessions/d5256bd7-1cab-4399-97a0-9c115a2f97cb
Done in 6425bab. Added 3 new BOOKMARK unit tests targeting the behavior introduced in PR #2505:
Total BOOKMARK test count is now 5 (2 existing + 3 new); all 41 unit tests pass. |
| mock_w.resource_version = "100" | ||
|
|
||
| def fake_stream(func, **kw): | ||
| yield {"type": "BOOKMARK", "object": bookmark_obj, "raw_object": bookmark_obj} |
There was a problem hiding this comment.
this fake_stream is NOT really used, if we change bookmark_obj's resourceVersion to "200" (from the current "100"), the test still passes.
There was a problem hiding this comment.
Fixed in a858453. mock_w.resource_version now starts at "5" (the initial-list RV), and fake_stream updates it to "100" before yielding the BOOKMARK event — mirroring how Watch.unmarshal_event sets resource_version before yielding. The test now fails if BOOKMARK handling is broken, because the informer has to actually read the updated value from the watch rather than finding "100" already set before the stream runs.
|
@copilot please address the comment on the bookmark test |
…rce_version to list RV and update in fake_stream Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> Agent-Logs-Url: https://github.com/kubernetes-client/python/sessions/eed1f863-e80c-4b7a-9901-26288418183e
|
It looks good to me, I'll have @roycaihw take a look. |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, Copilot, yliaog The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
Python clients wanting a local cache of Kubernetes resources had to implement their own watch loops, reconnection logic, and thread management. This adds a
SharedInformeranalogous to the Java and JavaScript client implementations.New package:
kubernetes.informerObjectCache(cache.py) — thread-safe in-memory store keyed bynamespace/name; exposeslist(),get(),get_by_key(),list_keys()SharedInformer(informer.py) — daemon thread running list-then-watch loop with:ApiExceptionor other errorsADDED,MODIFIED,DELETED,BOOKMARK, andERRORresourceVersiontracking: reused on reconnect; reset on 410 Gone for a fresh re-listlist_funccall everyresync_periodseconds even when the cluster is quiet (viatimeout_secondson the watch); resync firesADDED/MODIFIED/DELETEDby diffing old vs new stateTesting
kubernetes/test/test_informer.py, covering cache behaviour, event handlers, watch loop, BOOKMARK handling,resourceVersiontracking, 410 Gone recovery, periodic resync, and scenarios analogous to the JavaScript, Java, and client-go reference tests. BOOKMARK-specific tests include:_resource_versionon the informer (exercising Watch's BOOKMARK-awareresource_versionextraction)_resource_versionto the latest onekubernetes/e2e_test/test_informer.py(auto-skipped when no cluster is available):start()ADDEDevent firing and cache population when a ConfigMap is createdMODIFIEDevent firing and updated data verified when a ConfigMap is patchedDELETEDevent firing and cache removal when a ConfigMap is deletedresourceVersionadvancing after real watch events are receivedMODIFIEDfor existing cached objects (test_resync_fires_modified_for_existing_objects)💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.