Skip to content

Commit b240b03

Browse files
author
Yorick Gruijthuijzen
committed
Added support for copying files to init Containers.
1 parent 1705ced commit b240b03

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

plugins/module_utils/copy.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _run_from_pod(self, cmd):
9696
return error, stdout, stderr
9797
except Exception as e:
9898
self.module.fail_json(
99-
msg="Error while running/parsing from pod {1}/{2} command='{0}' : {3}".format(
99+
msg="Error while running/parsing from pod {0}/{1} command='{2}' : {3}".format(
100100
self.namespace, self.name, cmd, to_native(e)
101101
)
102102
)
@@ -435,11 +435,13 @@ def _fail(exc):
435435

436436
try:
437437
result = svc.client.get(resource, name=name, namespace=namespace)
438-
containers = [
439-
c["name"] for c in result.to_dict()["status"]["containerStatuses"]
440-
]
441-
if container and container not in containers:
438+
containers = dict({
439+
c["name"]: c for cl in ['initContainerStatuses','containerStatuses'] for c in result.to_dict().get("status").get(cl, [])
440+
})
441+
if container and container not in containers.keys():
442442
module.fail_json(msg="Pod has no container {0}".format(container))
443-
return containers
443+
if container and container in containers and not bool(containers[container]['started']):
444+
module.fail_json(msg="Pod container {0} is not started".format(container))
445+
return containers.keys()
444446
except Exception as exc:
445447
_fail(exc)

0 commit comments

Comments
 (0)