Skip to content

Commit 6f18eb8

Browse files
committed
k8s: use mv to prevent scenario getting cut off
We use this following to check for the scenario file: while [ ! -f /shared/archive.pyz ]; do echo "Waiting for /shared/archive.pyz to exist..." sleep 2 done I suspect this may cut off longer-running copy commands. Using mv we make sure all the data is copied over, and then we `mv` the file into place.
1 parent d9b3e1d commit 6f18eb8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/warnet/k8s.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def write_file_to_container(
368368
):
369369
namespace = get_default_namespace_or(namespace)
370370
sclient = get_static_client()
371-
exec_command = ["sh", "-c", f"cat > {dst_path}"]
371+
exec_command = ["sh", "-c", f"cat > {dst_path}.tmp"]
372372
try:
373373
res = stream(
374374
sclient.connect_get_namespaced_pod_exec,
@@ -384,6 +384,18 @@ def write_file_to_container(
384384
)
385385
res.write_stdin(data)
386386
res.close()
387+
rename_command = ["sh", "-c", f"mv {dst_path}.tmp {dst_path}"]
388+
stream(
389+
sclient.connect_get_namespaced_pod_exec,
390+
pod_name,
391+
namespace,
392+
command=rename_command,
393+
container=container_name,
394+
stdin=False,
395+
stderr=True,
396+
stdout=True,
397+
tty=False,
398+
)
387399
print(f"Successfully copied data to {pod_name}({container_name}):{dst_path}")
388400
return True
389401
except Exception as e:

0 commit comments

Comments
 (0)