How to parametrise volumes with @script() ? #738
-
I'm trying to convert some fully functional in house AW source to Hera. - name: do-some-stuff-template
inputs:
parameters:
- name: persistedVolume
script:
image: python:3.9-alpine
source: |
<snip ... some python code ...snip>
volumeMounts:
- name: workdir
mountPath: "{{inputs.parameters.persistedVolume}}" # What is the Hera equivalent ? After taking some inspiration from Hera's "script auto infer" example (and some dark magic incantations, since I have to admit that I the underlying inference mechanism totally eludes me) I dared trying the following: @script(
image="python:3.9-alpine",
volume=Volume(
name="workdir",
mount_path=persisted_volume, # How to transmit this argument (at build time) ?
),
)
def do_some_stuff(persisted_volume): # NameError: name persisted_volume is not defined
<snip ... some python code ...snip> Alas this fails (not enough chicken blood spilled?). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Unfortunately right now the easiest way to do this is a mix of Argo syntax and the @script(
image="python:3.9-alpine",
inputs=[Parameter(name="persistedVolume")], # specify an input to the template here instead of as a function arg
volume=Volume(
name="workdir",
mount_path="{{inputs.parameters.persistedVolume}}", # refer to the input with Argo syntax
),
)
def do_some_stuff(): # persisted_volume (probably) not needed here
<snip ... some python code ...snip> |
Beta Was this translation helpful? Give feedback.
-
Thank you @elliotgunton . Except for the typo (the trailing third curly bracket, |
Beta Was this translation helpful? Give feedback.
-
@elliotgunton Also I wanted to mention (at least with version 5.6.0) that it seems that the calling prototype seems to require the mention of the argument. That is one has to write def do_some_stuff(persisted_volume): # persisted_volume MUST be mentioned here
# (although it is only used in the `@script()` section) Otherwise one gets a Here is a full example for you to quickly experiment from hera.workflows import DAG, Parameter, script, Workflow
@script(
image="{{inputs.parameters.image}}",
)
def test(): # FAILS at submission stage with message:
# failed to resolve {{inputs.parameters.image}}`
# but the following definitions smoothly accepts submission
# def test(image):
...
with Workflow(generate_name="fail-", entrypoint="main") as w:
with DAG(name="main"):
t1 = test(
arguments=Parameter(
name="image",
value="pyton;3.9-alpine",
),
)
w.create() Thanks again. |
Beta Was this translation helpful? Give feedback.
Unfortunately right now the easiest way to do this is a mix of Argo syntax and the
inputs
present in the script decorator (we're working on improving this!)