client: add Kubernetes-aware retry helpers#2634
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. |
|
Welcome @sttts! |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sttts 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 |
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
ee00eac to
ec56a76
Compare
What
Add Kubernetes-aware retry helper modules modeled after
k8s.io/client-go/util/retryand the client-go REST Retry-After behavior.This PR provides only the non-generated helper surface:
kubernetes.utils.retrywith sync retry helpers:Backoff,DEFAULT_BACKOFF,DEFAULT_RETRY,on_error(...),retry_on_conflict(...),on_retry_after_error(...), and Retry-After helperskubernetes.aio.utils.retrywith the same helper surface for the separately packaged AIO client, source-linked to the sync helper module so the wheel gets an independent copy at build timekubernetes.utilsandkubernetes.aio.utilssetup-asyncio.pypackaging forkubernetes.aio.utilsThe generated REST/Configuration integration is intentionally not part of this PR. That follows in kubernetes-client/gen#304 after these helper modules exist.
Why
The generated Python client exposes transport-level urllib3 retries, but it does not provide Kubernetes-aware retry helpers equivalent to client-go. Transport retries cannot re-read objects before retrying a write after a 409 conflict, and callers currently have to duplicate retry/backoff behavior.
For writes, this PR provides explicit helpers so callers can re-read the object inside the retry function before submitting an update or patch after a 409 conflict.
The helper semantics follow client-go retry behavior closely, including
wait.Backoffstep/cap behavior and Retry-After delay selection helpers for the later generated REST integration.Follow-up
Tests
.venv/bin/python -m unittest kubernetes.utils.retry_test kubernetes.aio.utils.retry_test.venv/bin/python -m pytest -q kubernetes/utils/retry_test.py kubernetes/aio/utils/retry_test.py.venv/bin/python -m pycodestyle kubernetes/utils/retry.py kubernetes/aio/utils/retry.py kubernetes/utils/retry_test.py kubernetes/aio/utils/retry_test.py kubernetes/utils/__init__.py kubernetes/aio/utils/__init__.pysetup-asyncio.py build_pycheck confirmedkubernetes/aio/utils/retry.pyis copied as a regular file, not a symlink, in the build outputgit diff --check