-
Notifications
You must be signed in to change notification settings - Fork 41.1k
[WIP] refactor: clean up the watch server handlers #131325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Tue Apr 15 19:35:15 UTC 2025. |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions 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. |
8d152e2
to
8be1091
Compare
Needs rebase on top of #131339 |
8be1091
to
d3b4c49
Compare
cf15132
to
5767ca0
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: karlkfi The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5767ca0
to
3f1da78
Compare
3f1da78
to
804ea32
Compare
- Use testify assert & require - Use io instead of ioutil - Use named sub-tests, instead of just loops - Fix flaky tests that weren't waiting for Watch to be called before sending events. - Validate url.Parse does not error in tests. - Close response body - Add apitesting http methods for handling response body and websocket read, drain, and closure. - Pass test context to http requests
- Fix client-go Watch and WatchList to cancel the request on error. This frees up resources in the client and server, allowing re-use of the TCP connection. - Fix net.IsProbableEOF to catch read failures on closed responses. This prevents StreamWatcher.receive from sending a Decode error event when the response body has been closed asynchronously, which prevents the watch client from sending a decode error on the watch result channel after the watcher has been stopped by the event consumer or after the watch context has been cancelled or timed out. - Update the apiserver watch endpoint tests to validate that the storage watcher result channel, timeout done channel, and response body are closed on both success and failure. - Update the client-go rest tests to stop the watcher and wait for the result channel to close. - Add channel testing helper functions to k8s.io/client-go/util/testing
804ea32
to
047331d
Compare
- Always stop the watcher when done reading events from the result channel. ListResource already stops the watch, but it's multiple layers above, which means unit tests of the internal methods need to replicate that behavior. So this change simplifies testing and ensures the watcher is stopped at least once. This should also make it easier to simplify the WatchServer in the future. - Avoid calling Done & ResultChan multiple times, to reduce locking and memory allocations. - Replace the TimeoutFactory with a Context, to reduce complexity. - Add a done channel to the WatchServer to handle cleanup: stop the context and the storage watcher. - Fix some flaky tests that were trying to use SimpleStorage.fakeWatcher before Watch was called.
047331d
to
bf78458
Compare
@karlkfi: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions 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. I understand the commands that are listed here. |
PR needs rebase. Instructions 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. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
What type of PR is this?
/kind cleanup
/sig api-machinery
What this PR does / why we need it
channel. ListResource already stops the watch, but it's multiple
layers above, which means unit tests of the internal methods need
to replicate that behavior. So this change simplifies testing and
ensures the watcher is stopped at least once. This should also make
it easier to simplify the WatchServer in the future.
and memory allocations.
stop the context and the storage watcher.
before Watch was called.
and closure.
Does this PR introduce a user-facing change?
Dependencies