Add SharedInformer implementation to python-client#2515
Add SharedInformer implementation to python-client#2515
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
…example Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@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 |
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, andERRORBOOKMARKevent support: handlers receive the raw bookmark object (containing the updatedresourceVersion); the cache is not modifiedresourceVersiontracking: the most recentresourceVersion(updated by every event including BOOKMARKs) is stored and reused on reconnect, avoiding unnecessary full re-lists; a 410 Gone response resets the stored version and triggers a fresh re-listMODIFIEDfor all cached objects)Usage
SharedInformeris now exposed via the top-levelkubernetespackage (kubernetes.informer).Testing
Unit tests are in
kubernetes/test/test_informer.pyand cover the cache, key function, event handlers, watch loop behaviour, BOOKMARK handling, andresourceVersiontracking including 410 Gone recovery.End-to-end tests are in
kubernetes/e2e_test/test_informer.pyand run against a real cluster (automatically skipped when no cluster is available). They cover:start()ADDEDevent firing and cache population when a ConfigMap is createdMODIFIEDevent firing when a ConfigMap is patchedDELETEDevent firing and cache removal when a ConfigMap is deletedresourceVersionadvancing after real watch events are receivedOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.