Skip to content

Commit

Permalink
k8s: stream config data in chunks to aoid pipe buffer limits
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Apr 3, 2024
1 parent dc3cf14 commit 3a4eb04
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/backends/kubernetes/kubernetes_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,15 @@ def write_service_config(self, service_name: str, tar_buffer: IO[bytes], destina
tty=False,
_preload_content=False
)
resp.write_stdin(tar_buffer.getvalue())
# Stream data in chunks, otherwise this breaks at 196608 bytes
# https://unix.stackexchange.com/questions/11946/how-big-is-the-pipe-buffer
# https://stackoverflow.com/a/53904789/1653320
tar_data = tar_buffer.getvalue()
chunk_size = 1024 * 32 # 32 kb
for i in range(0, len(tar_data), chunk_size):
chunk = tar_data[i:i+chunk_size]
resp.write_stdin(chunk)
self.log.info(f"Wrote {len(chunk)} bytes")
resp.close()
self.log.info(f"Finished writing tarball for {service_name}, unpacking...")
# Unpack the archive
Expand Down

0 comments on commit 3a4eb04

Please sign in to comment.