-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get_artifact
for template invocator use
#1284
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e3a95d
Add `get_artifact` method to IOMixin
elliotgunton fed8cb9
Add example for artifacts in DAGs
elliotgunton 031af52
Add on-cluster test for DAG artifact example
elliotgunton ad672cd
fixup! Add example for artifacts in DAGs
elliotgunton 9fb42fb
Fix cicd steps
elliotgunton b4d8894
Fix tests
elliotgunton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,121 @@ | ||
# Artifacts In Dags | ||
|
||
|
||
|
||
This example shows how to use artifacts as inputs and outputs of DAGs. | ||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import DAG, Artifact, Container, Workflow | ||
|
||
with Workflow( | ||
generate_name="artifacts-in-dags-", | ||
entrypoint="runner-dag", | ||
) as w: | ||
hello_world_to_file = Container( | ||
name="hello-world-to-file", | ||
image="busybox", | ||
command=["sh", "-c"], | ||
args=["sleep 1; echo hello world | tee /tmp/hello_world.txt"], | ||
outputs=[Artifact(name="hello-art", path="/tmp/hello_world.txt")], | ||
) | ||
print_message_from_file = Container( | ||
name="print-message-from-file", | ||
image="alpine:latest", | ||
command=["sh", "-c"], | ||
args=["cat /tmp/message"], | ||
inputs=[Artifact(name="message", path="/tmp/message")], | ||
) | ||
|
||
# First DAG generates an artifact from a task, and "lifts" it out as an output of the DAG template itself | ||
with DAG( | ||
name="generate-artifact-dag", | ||
outputs=[Artifact(name="hello-file", from_="{{tasks.hello-world-to-file.outputs.artifacts.hello-art}}")], | ||
) as d1: | ||
hello_world_to_file() | ||
|
||
# Second DAG takes an artifact input, and the task references it using `get_artifact` | ||
with DAG(name="consume-artifact-dag", inputs=[Artifact(name="hello-file-input")]) as d2: | ||
print_message_from_file( | ||
arguments=d2.get_artifact("hello-file-input").with_name("message"), | ||
) | ||
|
||
# Third DAG orchestrates the first two, by creating tasks by "calling" the objects | ||
with DAG(name="runner-dag"): | ||
generator_dag = d1() | ||
consumer_dag = d2(arguments=generator_dag.get_artifact("hello-file").with_name("hello-file-input")) | ||
|
||
generator_dag >> consumer_dag | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: artifacts-in-dags- | ||
spec: | ||
entrypoint: runner-dag | ||
templates: | ||
- container: | ||
args: | ||
- sleep 1; echo hello world | tee /tmp/hello_world.txt | ||
command: | ||
- sh | ||
- -c | ||
image: busybox | ||
name: hello-world-to-file | ||
outputs: | ||
artifacts: | ||
- name: hello-art | ||
path: /tmp/hello_world.txt | ||
- container: | ||
args: | ||
- cat /tmp/message | ||
command: | ||
- sh | ||
- -c | ||
image: alpine:latest | ||
inputs: | ||
artifacts: | ||
- name: message | ||
path: /tmp/message | ||
name: print-message-from-file | ||
- dag: | ||
tasks: | ||
- name: hello-world-to-file | ||
template: hello-world-to-file | ||
name: generate-artifact-dag | ||
outputs: | ||
artifacts: | ||
- from: '{{tasks.hello-world-to-file.outputs.artifacts.hello-art}}' | ||
name: hello-file | ||
- dag: | ||
tasks: | ||
- arguments: | ||
artifacts: | ||
- from: '{{inputs.artifacts.hello-file-input}}' | ||
name: message | ||
name: print-message-from-file | ||
template: print-message-from-file | ||
inputs: | ||
artifacts: | ||
- name: hello-file-input | ||
name: consume-artifact-dag | ||
- dag: | ||
tasks: | ||
- name: generate-artifact-dag | ||
template: generate-artifact-dag | ||
- arguments: | ||
artifacts: | ||
- from: '{{tasks.generate-artifact-dag.outputs.artifacts.hello-file}}' | ||
name: hello-file-input | ||
depends: generate-artifact-dag | ||
name: consume-artifact-dag | ||
template: consume-artifact-dag | ||
name: runner-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,64 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: artifacts-in-dags- | ||
spec: | ||
entrypoint: runner-dag | ||
templates: | ||
- container: | ||
args: | ||
- sleep 1; echo hello world | tee /tmp/hello_world.txt | ||
command: | ||
- sh | ||
- -c | ||
image: busybox | ||
name: hello-world-to-file | ||
outputs: | ||
artifacts: | ||
- name: hello-art | ||
path: /tmp/hello_world.txt | ||
- container: | ||
args: | ||
- cat /tmp/message | ||
command: | ||
- sh | ||
- -c | ||
image: alpine:latest | ||
inputs: | ||
artifacts: | ||
- name: message | ||
path: /tmp/message | ||
name: print-message-from-file | ||
- dag: | ||
tasks: | ||
- name: hello-world-to-file | ||
template: hello-world-to-file | ||
name: generate-artifact-dag | ||
outputs: | ||
artifacts: | ||
- from: '{{tasks.hello-world-to-file.outputs.artifacts.hello-art}}' | ||
name: hello-file | ||
- dag: | ||
tasks: | ||
- arguments: | ||
artifacts: | ||
- from: '{{inputs.artifacts.hello-file-input}}' | ||
name: message | ||
name: print-message-from-file | ||
template: print-message-from-file | ||
inputs: | ||
artifacts: | ||
- name: hello-file-input | ||
name: consume-artifact-dag | ||
- dag: | ||
tasks: | ||
- name: generate-artifact-dag | ||
template: generate-artifact-dag | ||
- arguments: | ||
artifacts: | ||
- from: '{{tasks.generate-artifact-dag.outputs.artifacts.hello-file}}' | ||
name: hello-file-input | ||
depends: generate-artifact-dag | ||
name: consume-artifact-dag | ||
template: consume-artifact-dag | ||
name: runner-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,42 @@ | ||
"""This example shows how to use artifacts as inputs and outputs of DAGs.""" | ||
|
||
from hera.workflows import DAG, Artifact, Container, Workflow | ||
|
||
with Workflow( | ||
generate_name="artifacts-in-dags-", | ||
entrypoint="runner-dag", | ||
) as w: | ||
hello_world_to_file = Container( | ||
name="hello-world-to-file", | ||
image="busybox", | ||
command=["sh", "-c"], | ||
args=["sleep 1; echo hello world | tee /tmp/hello_world.txt"], | ||
outputs=[Artifact(name="hello-art", path="/tmp/hello_world.txt")], | ||
) | ||
print_message_from_file = Container( | ||
name="print-message-from-file", | ||
image="alpine:latest", | ||
command=["sh", "-c"], | ||
args=["cat /tmp/message"], | ||
inputs=[Artifact(name="message", path="/tmp/message")], | ||
) | ||
|
||
# First DAG generates an artifact from a task, and "lifts" it out as an output of the DAG template itself | ||
with DAG( | ||
name="generate-artifact-dag", | ||
outputs=[Artifact(name="hello-file", from_="{{tasks.hello-world-to-file.outputs.artifacts.hello-art}}")], | ||
) as d1: | ||
hello_world_to_file() | ||
|
||
# Second DAG takes an artifact input, and the task references it using `get_artifact` | ||
with DAG(name="consume-artifact-dag", inputs=[Artifact(name="hello-file-input")]) as d2: | ||
print_message_from_file( | ||
arguments=d2.get_artifact("hello-file-input").with_name("message"), | ||
) | ||
|
||
# Third DAG orchestrates the first two, by creating tasks by "calling" the objects | ||
with DAG(name="runner-dag"): | ||
generator_dag = d1() | ||
consumer_dag = d2(arguments=generator_dag.get_artifact("hello-file").with_name("hello-file-input")) | ||
|
||
generator_dag >> consumer_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: executor | ||
rules: | ||
- apiGroups: | ||
- argoproj.io | ||
resources: | ||
- workflowtaskresults | ||
verbs: | ||
- create | ||
- patch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: argo-executor-binding | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: executor | ||
subjects: | ||
- kind: ServiceAccount | ||
name: argo | ||
namespace: argo |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we're copying across all the fields in
get_parameter
, but only name in this function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably shouldn't copy everything in
get_parameter
, as all the other fields are irrelevant when used as an argument