-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement get_parameter API on IO mixin and add tests (#876)
**Pull Request Checklist** - [x] Fixes #816 - [x] Tests added - [x] Documentation/examples added - [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR title Implements the `get_parameter` API on the `IOMixin`. This allows clients that need parameters in `arguments` fields to get the parameter object from DAGs, Steps, etc. This helps avoid the need to write `{{inputs.parameters.whatever}}` explicitly. `get_parameter` _assumes_ that clients want to use a parameter as input, so the value field is set accordingly Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
- Loading branch information
1 parent
c8980bd
commit 614d364
Showing
11 changed files
with
277 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Callable Dag With Param Get | ||
|
||
|
||
|
||
|
||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from typing_extensions import Annotated | ||
|
||
from hera.workflows import DAG, Parameter, Workflow, script | ||
|
||
|
||
@script(constructor="runner") | ||
def hello_with_output(name: str) -> Annotated[str, Parameter(name="output-message")]: | ||
return "Hello, {name}!".format(name=name) | ||
|
||
|
||
with Workflow( | ||
generate_name="callable-dag-", | ||
entrypoint="calling-dag", | ||
) as w: | ||
with DAG( | ||
name="my-dag-with-outputs", | ||
inputs=Parameter(name="my-dag-input"), | ||
outputs=Parameter( | ||
name="my-dag-output", | ||
value_from={"parameter": "{{hello.outputs.parameters.output-message}}"}, | ||
), | ||
) as my_dag: | ||
# Here, get_parameter searches through the *inputs* of my_dag | ||
hello_with_output(name="hello", arguments={"name": f"hello {my_dag.get_parameter('my-dag-input')}"}) | ||
|
||
with DAG(name="calling-dag") as d: | ||
t1 = my_dag(name="call-1", arguments={"my-dag-input": "call-1"}) | ||
# Here, t1 is a Task from the called dag, so get_parameter is called on the Task to get the output parameter! 🚀 | ||
t2 = my_dag(name="call-2", arguments=t1.get_parameter("my-dag-output").with_name("my-dag-input")) | ||
t1 >> t2 | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: callable-dag- | ||
spec: | ||
entrypoint: calling-dag | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: name | ||
value: hello {{inputs.parameters.my-dag-input}} | ||
name: hello | ||
template: hello-with-output | ||
inputs: | ||
parameters: | ||
- name: my-dag-input | ||
name: my-dag-with-outputs | ||
outputs: | ||
parameters: | ||
- name: my-dag-output | ||
valueFrom: | ||
parameter: '{{hello.outputs.parameters.output-message}}' | ||
- inputs: | ||
parameters: | ||
- name: name | ||
name: hello-with-output | ||
script: | ||
args: | ||
- -m | ||
- hera.workflows.runner | ||
- -e | ||
- examples.workflows.callable_dag_with_param_get:hello_with_output | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: '{{inputs.parameters}}' | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: my-dag-input | ||
value: call-1 | ||
name: call-1 | ||
template: my-dag-with-outputs | ||
- arguments: | ||
parameters: | ||
- name: my-dag-input | ||
value: '{{tasks.call-1.outputs.parameters.my-dag-output}}' | ||
depends: call-1 | ||
name: call-2 | ||
template: my-dag-with-outputs | ||
name: calling-dag | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: callable-dag- | ||
spec: | ||
entrypoint: calling-dag | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: name | ||
value: hello {{inputs.parameters.my-dag-input}} | ||
name: hello | ||
template: hello-with-output | ||
inputs: | ||
parameters: | ||
- name: my-dag-input | ||
name: my-dag-with-outputs | ||
outputs: | ||
parameters: | ||
- name: my-dag-output | ||
valueFrom: | ||
parameter: '{{hello.outputs.parameters.output-message}}' | ||
- inputs: | ||
parameters: | ||
- name: name | ||
name: hello-with-output | ||
script: | ||
args: | ||
- -m | ||
- hera.workflows.runner | ||
- -e | ||
- examples.workflows.callable_dag_with_param_get:hello_with_output | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: '{{inputs.parameters}}' | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: my-dag-input | ||
value: call-1 | ||
name: call-1 | ||
template: my-dag-with-outputs | ||
- arguments: | ||
parameters: | ||
- name: my-dag-input | ||
value: '{{tasks.call-1.outputs.parameters.my-dag-output}}' | ||
depends: call-1 | ||
name: call-2 | ||
template: my-dag-with-outputs | ||
name: calling-dag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing_extensions import Annotated | ||
|
||
from hera.workflows import DAG, Parameter, Workflow, script | ||
|
||
|
||
@script(constructor="runner") | ||
def hello_with_output(name: str) -> Annotated[str, Parameter(name="output-message")]: | ||
return "Hello, {name}!".format(name=name) | ||
|
||
|
||
with Workflow( | ||
generate_name="callable-dag-", | ||
entrypoint="calling-dag", | ||
) as w: | ||
with DAG( | ||
name="my-dag-with-outputs", | ||
inputs=Parameter(name="my-dag-input"), | ||
outputs=Parameter( | ||
name="my-dag-output", | ||
value_from={"parameter": "{{hello.outputs.parameters.output-message}}"}, | ||
), | ||
) as my_dag: | ||
# Here, get_parameter searches through the *inputs* of my_dag | ||
hello_with_output(name="hello", arguments={"name": f"hello {my_dag.get_parameter('my-dag-input')}"}) | ||
|
||
with DAG(name="calling-dag") as d: | ||
t1 = my_dag(name="call-1", arguments={"my-dag-input": "call-1"}) | ||
# Here, t1 is a Task from the called dag, so get_parameter is called on the Task to get the output parameter! 🚀 | ||
t2 = my_dag(name="call-2", arguments=t1.get_parameter("my-dag-output").with_name("my-dag-input")) | ||
t1 >> t2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters