Repository navigation
Handle pod logs cut mid-character by limitBytes - #2761
carterpewpew wants to merge 1 commit into
Conversation
|
Welcome @carterpewpew! |
|
/assign |
|
@carterpewpew could you fix it in the upstream openapi-generator? then we don't need to carry a patch in this repo. |
chala2001
left a comment
There was a problem hiding this comment.
Tested this on Python 3.12. The new tests fail on master and pass with this change, and a cut multi-byte char at the end is now just dropped. Looks good to me. It needs a rebase though, the only conflict is in kubernetes/aio/test/test_generated_api.py.
read_namespaced_pod_log(limit_bytes=N) returns the first N bytes of the log, and the API server does not align that cut to a character boundary. When it falls inside a multi-byte UTF-8 character, response_deserialize() raised UnicodeDecodeError and the caller lost the whole log. When the strict decode fails, decode again with an incremental decoder and final=False. That leaves out only an incomplete sequence at the very end and still raises for any other invalid byte, so valid responses and genuinely bad data behave as before. The sync and asyncio api_client.py files are generated, so the change is also kept in scripts/api_client_patch.diff and scripts/api_client_asyncio_patch.diff, which the update scripts apply. Signed-off-by: Jathavedhan M <jathavedhan.m@ibm.com>
58ce1d8 to
d24bbc7
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: carterpewpew 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 |
|
Makes sense. The decode comes from openapi-generator's python |
What type of PR is this?
/kind bug
What this PR does / why we need it:
read_namespaced_pod_log(limit_bytes=N)returns the first N bytes of the log, and the API server does not align that cut to a character boundary. When the cut lands inside a multi-byte UTF-8 character,response_deserialize()raisesUnicodeDecodeErrorand the whole log is lost.This still happens on 1.37. The decode moved from
rest.py(where the trace in the issue points) toApiClient.response_deserialize(). With a log body ofcafé €cut one byte short, 37.0.1 fails with'utf-8' codec can't decode bytes in position 6-7: unexpected end of data.When the strict decode fails, the body is decoded again with an incremental decoder and
final=False. That leaves out only an incomplete sequence at the very end, so the example above returnscafé. Any other invalid byte still raisesUnicodeDecodeError, as before. Valid responses take the same strict path as today.bytes,fileand_preload_content=Falseresponses are not affected.api_client.pyis generated, so the same change is kept inscripts/api_client_patch.diffandscripts/api_client_asyncio_patch.diff, andupdate-client.sh/update-client-asyncio.shapply them after generation, like the keepalive and client-go retry patches.Which issue(s) this PR fixes:
Fixes #2756
Special notes for your reviewer:
The new tests go through
CoreV1Api.read_namespaced_pod_logfor both clients: the sync one with a mocked pool manager, the asyncio one against the aiohttp test server already intest_generated_api.py. The truncation tests fail on master with the error above. The invalid-byte tests fail if the decode is relaxed toerrors="ignore".Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
This PR was made with AI assistance, but every change has been reviewed line by line.