This example shows how to use pod_spec_patch to update the cpu/memory requests for the init container.
This is useful if you want to load a large artifact, but the init container does not have enough memory to load it. This
problem is described in the
Argo Artifacts Walkthrough.
In Hera, the resources field of the template only sets the main container resources. We can use a pod_spec_patch
to set the init container resources.
importjsonfromhera.workflowsimport(Artifact,NoneArchiveStrategy,Resources,Steps,Workflow,script,)@script(outputs=Artifact(name="out-art",path="/tmp/file",archive=NoneArchiveStrategy()),resources=Resources(memory_request="2Gi"),)defwriter():withopen("/tmp/file","w")asf:f.write("Hello, world!")@script(inputs=Artifact(name="in-art",path="/tmp/file"),resources=Resources(memory_request="2Gi"),pod_spec_patch=json.dumps({"initContainers":[{"name":"init","resources":{"requests":{"memory":"2Gi"}}}]}),)defconsumer():withopen("/tmp/file","r")asf:print(f.readlines())# prints `Hello, world!` to `stdout`withWorkflow(generate_name="artifact-",entrypoint="steps")asw:withSteps(name="steps"):w_=writer()c=consumer(arguments={"in-art":w_.get_artifact("out-art")})