Add SharedInformer implementation to python-client#2515
Add SharedInformer implementation to python-client#2515
Conversation
…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 |
|
@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 ( |
| kw["field_selector"] = self._field_selector | ||
| return kw | ||
|
|
||
| def _fire(self, event_type, obj): |
There was a problem hiding this comment.
Please document what fire means (execute handler callbacks)
kubernetes/informer/informer.py
Outdated
| self._fire(BOOKMARK, event.get("raw_object", obj)) | ||
| elif evt_type == ERROR: | ||
| self._fire(ERROR, obj) | ||
| # Periodic resync: full re-list from the API server, firing |
There was a problem hiding this comment.
This periodic resync is placed after a watch event. Does it mean that the resync won't be triggered, even if the time passes, if there is no new watch event for a while?
| t.start() | ||
| for t in threads: | ||
| t.join() | ||
| self.assertEqual(errors, []) |
There was a problem hiding this comment.
Also verify the content in the cache?
|
|
||
| modified = [] | ||
| informer = SharedInformer(list_func=list_func) | ||
| informer.add_event_handler(MODIFIED, modified.append) |
There was a problem hiding this comment.
Shall we also confirm that no other handler (CREATED, etc.) was fired?
kubernetes/e2e_test/test_informer.py
Outdated
| self.addCleanup(inf.stop) | ||
|
|
||
| self._wait_in_cache(inf, "default/" + name) | ||
| self.assertEqual(_name_of(inf.cache.get_by_key("default/" + name)), name) |
There was a problem hiding this comment.
Other than the name, shall we also verify the data of the stored configmap, to ensure the cache was correctly populated?
kubernetes/e2e_test/test_informer.py
Outdated
| name=name, namespace="default", body={"data": {"k": "updated"}} | ||
| ) | ||
| self._expect(seen, "MODIFIED/" + name) | ||
| self.assertIsNotNone(inf.cache.get_by_key("default/" + name)) |
There was a problem hiding this comment.
Shall we also confirm the updated data for this modified configmap?
|
This is awesome. Thanks! Should I tag the bot when I leave comments for it to react? Also I wonder if it supports squashing commits to clean up at some point. |
|
@copilot please address code review comments. |
|
@roycaihw Thanks for the review. I believe that Prow automatically squashes the commits when it merges? |
|
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. |
…ertions, e2e data checks Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
@roycaihw I think that all your comments were addressed, can you recheck? |
_fire()explaining it executes handler callbackstimeout_seconds=resync_periodto Watch so the stream exits when resync is due; move resync check to after the stream loop (outside the event iteration)test_thread_safety: add assertions verifying the cache actually holds every object written by the concurrent threadstest_watch_disruption_existing_items_fire_modified_after_relist: register ADDED/DELETED handlers; assert ADDED fires exactly once (initial list) and DELETED fires zero times when an item is present in both liststest_cache_populated_after_start: verify the cached object'sdatafield, not just its nametest_modified_event_and_cache_refresh: verify the cached object holds the updateddatapayload after a patch💬 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.