kubernetes-client/javascript
cpFromPod fails with 'Unexpected end of data' error due to gzipped tar output
Summary
Context: The
cpFromPodmethod in theCpclass copies files from a Kubernetes pod to the local filesystem by executing a tar command inside the pod and streaming the output totar-fs.extract()for extraction.Bug: The tar command uses the
zflag to create a gzipped archive, buttar-fs.extract()does not automatically decompress gzipped data, causing extraction to fail.Actual vs. expected: When copying files from a pod, the operation fails with “Error: Unexpected end of data” instead of successfully extracting the files to the target directory.
Impact: The
cpFromPodfunctionality is completely broken, preventing users from copying files from pods to their local filesystem.
Code with bug
Evidence
The tar-fs package’s extract() method expects uncompressed tar data. When the tar command includes the z flag, it produces gzipped output that tar-fs.extract() cannot process, resulting in parsing errors. Unlike the previously used tar package which handled gzipped data automatically, tar-fs requires uncompressed tar streams.
Recommended fix
Remove the z flag from the tar command to produce uncompressed tar output that tar-fs.extract() can process. Change ['tar', 'zcf', '-'] to ['tar', 'cf', '-']. // <– FIX 🟢