Skip to content
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

Allow mounting volume for outputs #780

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/examples/workflows/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ task, consumer, takes this artifact, places it at its own `/file` path, and prin
artifacts:
- from: '{{tasks.writer.outputs.artifacts.out-art}}'
name: in-art
path: /tmp/file
depends: writer
name: consumer
template: consumer
Expand Down
1 change: 0 additions & 1 deletion docs/examples/workflows/artifact_with_fanout.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
artifacts:
- from: '{{tasks.writer.outputs.artifacts.out-art}}'
name: in-art
path: /tmp/file
depends: writer
name: fanout
template: fanout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Http
# Http



Expand Down
229 changes: 229 additions & 0 deletions docs/examples/workflows/script_annotations_artifact_custom_volume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# Script Annotations Artifact Custom Volume



This example will reuse the outputs volume across script steps.


=== "Hera"

```python linenums="1"
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


from hera.shared import global_config
from hera.workflows import (
Artifact,
EmptyDirVolume,
Parameter,
RunnerScriptConstructor,
Steps,
Workflow,
models as m,
script,
)

global_config.experimental_features["script_annotations"] = True
global_config.experimental_features["script_runner"] = True


@script(
constructor=RunnerScriptConstructor(
outputs_directory="/mnt/empty/dir",
volume_for_outputs=EmptyDirVolume(name="my-empty-dir"),
),
)
def output_artifact_empty_dir(
a_number: Annotated[int, Parameter(name="a_number")],
) -> Annotated[int, Artifact(name="successor_out")]:
return a_number + 1


@script(
constructor=RunnerScriptConstructor(), # Has no outputs
)
def use_artifact(successor_in: Annotated[int, Artifact(name="successor_in", loader=ArtifactLoader.json)]):
print(successor_in)


@script(
constructor=RunnerScriptConstructor(outputs_directory="/mnt/here"),
volume_mounts=[
m.VolumeMount(name="my-vol", mount_path="/mnt/here")
], # Mounting volume created outside of this script
)
def output_artifact_existing_vol(
a_number: Annotated[int, Parameter(name="a_number")],
) -> Annotated[int, Artifact(name="successor_out")]:
return a_number + 1


@script(
constructor=RunnerScriptConstructor(), # no outputs
volume_mounts=[
m.VolumeMount(name="my-vol", mount_path="/mnt/here")
], # Mounting volume created outside of this script
)
def use_artifact_existing_vol(
successor_in: Annotated[
int, Artifact(name="successor_in", path="/mnt/here/artifacts/successor_out", loader=ArtifactLoader.json)
],
):
print(successor_in)


with Workflow(
generate_name="test-output-annotations-",
entrypoint="my-steps",
volumes=[Volume(name="my-vol", size="1Gi")],
) as w:
with Steps(name="my-steps") as s:
out_to_empty_dir = output_artifact_empty_dir(arguments={"a_number": 3})
use_artifact(arguments=[out_to_empty_dir.get_artifact("successor_out").as_name("successor_in")])

out_to_my_vol = output_artifact_existing_vol(arguments={"a_number": 3})
use_artifact_existing_vol()
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: test-output-annotations-
spec:
entrypoint: my-steps
templates:
- name: my-steps
steps:
- - arguments:
parameters:
- name: a_number
value: '3'
name: output-artifact-empty-dir
template: output-artifact-empty-dir
- - arguments:
artifacts:
- from: '{{steps.output-artifact-empty-dir.outputs.artifacts.successor_out}}'
name: successor_in
name: use-artifact
template: use-artifact
- - arguments:
parameters:
- name: a_number
value: '3'
name: output-artifact-existing-vol
template: output-artifact-existing-vol
- - name: use-artifact-existing-vol
template: use-artifact-existing-vol
- inputs:
parameters:
- name: a_number
name: output-artifact-empty-dir
outputs:
artifacts:
- name: successor_out
path: /mnt/empty/dir/artifacts/successor_out
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_custom_volume:output_artifact_empty_dir
command:
- python
env:
- name: hera__script_annotations
value: ''
- name: hera__outputs_directory
value: /mnt/empty/dir
image: python:3.8
source: '{{inputs.parameters}}'
volumeMounts:
- mountPath: /mnt/empty/dir
name: my-empty-dir
volumes:
- emptyDir: {}
name: my-empty-dir
- inputs:
artifacts:
- name: successor_in
name: use-artifact
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_custom_volume:use_artifact
command:
- python
env:
- name: hera__script_annotations
value: ''
image: python:3.8
source: '{{inputs.parameters}}'
- inputs:
parameters:
- name: a_number
name: output-artifact-existing-vol
outputs:
artifacts:
- name: successor_out
path: /mnt/here/artifacts/successor_out
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_custom_volume:output_artifact_existing_vol
command:
- python
env:
- name: hera__script_annotations
value: ''
- name: hera__outputs_directory
value: /mnt/here
image: python:3.8
source: '{{inputs.parameters}}'
volumeMounts:
- mountPath: /mnt/here
name: my-vol
- inputs:
artifacts:
- name: successor_in
path: /mnt/here/artifacts/successor_out
name: use-artifact-existing-vol
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_custom_volume:use_artifact_existing_vol
command:
- python
env:
- name: hera__script_annotations
value: ''
image: python:3.8
source: '{{inputs.parameters}}'
volumeMounts:
- mountPath: /mnt/here
name: my-vol
volumeClaimTemplates:
- metadata:
name: my-vol
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Script Annotations Artifact Outputs Defaults



This example will reuse the outputs volume across script steps.


=== "Hera"

```python linenums="1"
from hera.workflows.artifact import ArtifactLoader
from hera.workflows.volume import Volume

try:
from typing import Annotated # type: ignore
except ImportError:
from typing_extensions import Annotated # type: ignore


from hera.shared import global_config
from hera.workflows import (
Artifact,
Parameter,
Steps,
Workflow,
models as m,
script,
)

global_config.experimental_features["script_annotations"] = True
global_config.experimental_features["script_runner"] = True


@script(constructor="runner")
def output_artifact(
a_number: Annotated[int, Parameter(name="a_number")],
) -> Annotated[int, Artifact(name="successor_out")]:
return a_number + 1


@script(constructor="runner")
def use_artifact(successor_in: Annotated[int, Artifact(name="successor_in", loader=ArtifactLoader.json)]):
print(successor_in)


with Workflow(
generate_name="test-output-annotations-",
entrypoint="my-steps",
volumes=[Volume(name="my-vol", size="1Gi")],
) as w:
with Steps(name="my-steps") as s:
out = output_artifact(arguments={"a_number": 3})
use_artifact(arguments=[out.get_artifact("successor_out").as_name("successor_in")])
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: test-output-annotations-
spec:
entrypoint: my-steps
templates:
- name: my-steps
steps:
- - arguments:
parameters:
- name: a_number
value: '3'
name: output-artifact
template: output-artifact
- - arguments:
artifacts:
- from: '{{steps.output-artifact.outputs.artifacts.successor_out}}'
name: successor_in
name: use-artifact
template: use-artifact
- inputs:
parameters:
- name: a_number
name: output-artifact
outputs:
artifacts:
- name: successor_out
path: /tmp/hera/outputs/artifacts/successor_out
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_outputs_defaults:output_artifact
command:
- python
env:
- name: hera__script_annotations
value: ''
- name: hera__outputs_directory
value: /tmp/hera/outputs
image: python:3.8
source: '{{inputs.parameters}}'
- inputs:
artifacts:
- name: successor_in
name: use-artifact
script:
args:
- -m
- hera.workflows.runner
- -e
- examples.workflows.script_annotations_artifact_outputs_defaults:use_artifact
command:
- python
env:
- name: hera__script_annotations
value: ''
image: python:3.8
source: '{{inputs.parameters}}'
volumeClaimTemplates:
- metadata:
name: my-vol
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
```

Loading
Loading