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>
|
@brendandburns are you experimenting or you really trying to get this working ... very interested in this 😄 |
|
@aojea I'm definitely really trying to get it working, but via copilot. |
well, that is a good kubecon talk 😄 we can always try to give him the last push 👍 |
|
@copilot e2e tests are timing out. Looks like the test that the resource version advances isn't working right. Please fix. |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Fixed in 90c2b02. The root cause was a race: The fix syncs |
Fixed in 90c2b02. The root cause was that The fix: |
|
@copilot can you add a test to validate that a full List call is made to the Kubernetes API server every resyncPeriod? |
…list Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in 5a8fef1. Two changes were needed: Implementation ( Test ( |
|
@copilot can you look at the tests here: https://github.com/kubernetes-client/javascript/blob/main/src/cache_test.ts and here: https://github.com/kubernetes-client/java/blob/master/util/src/test/java/io/kubernetes/client/informer/impl/DefaultSharedIndexInformerWireMockTest.java and make sure that there are similar tests for the python informer? Thanks |
…ires ADDED/MODIFIED/DELETED Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in b91f278. Reviewed both reference test files and added 7 new tests plus two implementation changes: Implementation changes (
New tests (analogous to reference tests):
All 33 tests pass. |
|
@copilot please examine the tests here: https://github.com/kubernetes/client-go/blob/c86837f7edbe99923f3296ca925eb1adc7189b39/tools/cache/shared_informer_test.go and find any tests that are missing from this client's informer unit tests and add them. Fix the code if they don't pass. |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in 25d1f12. Reviewed the client-go test file and added 5 new tests covering the scenarios we were missing:
The other client-go tests ( |
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(synced from the Watch before each handler fires) is stored and reused on reconnect, avoiding unnecessary full re-lists; a 410 Gone response resets the stored version and triggers a fresh re-listresync_periodseconds a fulllist_funccall is made to the API server; the result is diffed against the current cache andADDED/MODIFIED/DELETEDevents are fired for any changesADDEDfor new items,MODIFIEDfor existing items, andDELETEDfor items that have disappeared — matching the Java and JavaScript informer behaviourUsage
SharedInformeris now exposed via the top-levelkubernetespackage (kubernetes.informer).Testing
Unit tests are in
kubernetes/test/test_informer.py(38 tests) and cover the cache, key function, event handlers, watch loop behaviour, BOOKMARK handling,resourceVersiontracking including 410 Gone recovery, periodic resync triggering a full List call, and scenarios analogous to the JavaScriptcache_test.ts, JavaDefaultSharedIndexInformerWireMockTest, and Goshared_informer_test.go:namespace,label_selector, andfield_selectorare forwarded to both the list func and Watch kwargsresourceVersionkwarg after the initial listApiExceptionfires theERRORhandler and reconnects without re-listingERRORhandlerADDEDeventDELETEDTestSharedInformerMultipleRegistration)TestRemoveWhileActive)TestAddWhileActive)TestSharedInformerHandlerAbuse)MODIFIED(analogous to GoTestSharedInformerWatchDisruption)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.