From 1f79a03edf8b6ed8b16991363f4c262177f318aa Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 14 Feb 2022 11:51:25 +0530 Subject: [PATCH] Adding sleep 0 as workaround when copying files with kubectl exec (#378) Adding sleep 0 as workaround when copying files with kubectl exec SUMMARY For all the commands executed remotely, ** && sleep 0** will be appended as a workaround for all the commands to terminate properly: https://github.com/ansible/ansible/blob/16def8050a38510fe3e477a943a90a47a1bf3c8a/lib/ansible/plugins/action/__init__.py#L1243 Workaround will be applied in case of kubectl exec too: kubernetes.core/plugins/connection/kubectl.py Line 300 in b19ff9d super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) That is not the case in the case of the file copy executed by using kubectl exec, therefore it is possible for the kubectl exec to terminate before dd finishes properly causing the file to be truncated. ISSUE TYPE Bugfix Pull Request COMPONENT NAME changelogs/fragments/321-kubectl_sleep.yml plugins/connection/kubectl.py --- changelogs/fragments/321-kubectl_sleep.yml | 3 +++ plugins/connection/kubectl.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/321-kubectl_sleep.yml diff --git a/changelogs/fragments/321-kubectl_sleep.yml b/changelogs/fragments/321-kubectl_sleep.yml new file mode 100644 index 00000000..6839924b --- /dev/null +++ b/changelogs/fragments/321-kubectl_sleep.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- kubectl - wait for dd command to complete before proceeding (https://github.com/ansible-collections/kubernetes.core/pull/321). diff --git a/plugins/connection/kubectl.py b/plugins/connection/kubectl.py index a8fcbf5c..980b54a3 100644 --- a/plugins/connection/kubectl.py +++ b/plugins/connection/kubectl.py @@ -355,7 +355,7 @@ class Connection(ConnectionBase): [ self._play_context.executable, "-c", - "dd of=%s bs=%s%s" % (out_path, BUFSIZE, count), + "dd of=%s bs=%s%s && sleep 0" % (out_path, BUFSIZE, count), ] ) args = [to_bytes(i, errors="surrogate_or_strict") for i in args]