-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for volumes in WorkflowTemplate Spec (#629)
**Description of PR** Currently, there is bug with the `WorkflowTemplate` class where volumes are not being correctly built. Example: ```python from hera.workflows import WorkflowTemplate, DownwardAPIVolume from hera.workflows import models as m from hera.workflows import Script with WorkflowTemplate( name="test", volumes=[DownwardAPIVolume(name="podinfo", mount_path="/etc/podinfo", items=[m.DownwardAPIVolumeFile(field_ref=m.ObjectFieldSelector(field_path="metadata.annotations"), path="annotations")])] ) as w: Script(name="test", source="test", volume_mounts=[m.VolumeMount(name="podinfo", mount_path="/etc/podinfo")]) print(w.to_yaml()) ``` This generates: ```yaml ... volumes: name: podinfo ``` It should generate: ```yaml ... volumes: - downwardAPI: items: - fieldRef: fieldPath: metadata.annotations path: annotations name: podinfo ``` This works as expected for `Workflow` but not for `WorkflowTemplate`, this because for `WorkflowTemplate` `self._build_volumes()` is not being called and volume claims are not being built. This PR fixes this by generalising the logic used to build templates such that the same code is used for `Workflow` and `WorkflowTemplate`. Signed-off-by: Kurt Degiorgio <[email protected]> Co-authored-by: Kurt Degiorgio <[email protected]>
- Loading branch information
Showing
5 changed files
with
255 additions
and
22 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,129 @@ | ||
# Volume Mounts Wt | ||
|
||
|
||
|
||
|
||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import ( | ||
DAG, | ||
Parameter, | ||
Volume, | ||
WorkflowTemplate, | ||
models as m, | ||
script, | ||
) | ||
|
||
|
||
@script( | ||
inputs=Parameter(name="vol"), | ||
volume_mounts=[m.VolumeMount(name="{{inputs.parameters.vol}}", mount_path="/mnt/vol")], | ||
) | ||
def foo(): | ||
import os | ||
import subprocess | ||
|
||
print(os.listdir("/mnt")) | ||
print(subprocess.run("cd /mnt && df -h", shell=True, capture_output=True).stdout.decode()) | ||
|
||
|
||
with WorkflowTemplate( | ||
generate_name="volumes-", | ||
entrypoint="d", | ||
volumes=[ | ||
Volume(name="v1", mount_path="/mnt/v1", size="1Gi"), | ||
Volume(name="v2", mount_path="/mnt/v2", size="3Gi"), | ||
Volume(name="v3", mount_path="/mnt/v3", size="5Gi"), | ||
], | ||
) as w: | ||
with DAG(name="d"): | ||
foo(name="v1", arguments=Parameter(name="vol", value="v1")) | ||
foo(name="v2", arguments=Parameter(name="vol", value="v2")) | ||
foo(name="v3", arguments=Parameter(name="vol", value="v3")) | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: WorkflowTemplate | ||
metadata: | ||
generateName: volumes- | ||
spec: | ||
entrypoint: d | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v1 | ||
name: v1 | ||
template: foo | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v2 | ||
name: v2 | ||
template: foo | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v3 | ||
name: v3 | ||
template: foo | ||
name: d | ||
- inputs: | ||
parameters: | ||
- name: vol | ||
name: foo | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: 'import os | ||
|
||
import sys | ||
|
||
sys.path.append(os.getcwd()) | ||
|
||
import os | ||
|
||
import subprocess | ||
|
||
print(os.listdir(''/mnt'')) | ||
|
||
print(subprocess.run(''cd /mnt && df -h'', shell=True, capture_output=True).stdout.decode())' | ||
volumeMounts: | ||
- mountPath: /mnt/vol | ||
name: '{{inputs.parameters.vol}}' | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: v1 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi | ||
- metadata: | ||
name: v2 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
- metadata: | ||
name: v3 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi | ||
``` | ||
|
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,77 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: WorkflowTemplate | ||
metadata: | ||
generateName: volumes- | ||
spec: | ||
entrypoint: d | ||
templates: | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v1 | ||
name: v1 | ||
template: foo | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v2 | ||
name: v2 | ||
template: foo | ||
- arguments: | ||
parameters: | ||
- name: vol | ||
value: v3 | ||
name: v3 | ||
template: foo | ||
name: d | ||
- inputs: | ||
parameters: | ||
- name: vol | ||
name: foo | ||
script: | ||
command: | ||
- python | ||
image: python:3.8 | ||
source: 'import os | ||
import sys | ||
sys.path.append(os.getcwd()) | ||
import os | ||
import subprocess | ||
print(os.listdir(''/mnt'')) | ||
print(subprocess.run(''cd /mnt && df -h'', shell=True, capture_output=True).stdout.decode())' | ||
volumeMounts: | ||
- mountPath: /mnt/vol | ||
name: '{{inputs.parameters.vol}}' | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: v1 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi | ||
- metadata: | ||
name: v2 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
- metadata: | ||
name: v3 | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi |
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,35 @@ | ||
from hera.workflows import ( | ||
DAG, | ||
Parameter, | ||
Volume, | ||
WorkflowTemplate, | ||
models as m, | ||
script, | ||
) | ||
|
||
|
||
@script( | ||
inputs=Parameter(name="vol"), | ||
volume_mounts=[m.VolumeMount(name="{{inputs.parameters.vol}}", mount_path="/mnt/vol")], | ||
) | ||
def foo(): | ||
import os | ||
import subprocess | ||
|
||
print(os.listdir("/mnt")) | ||
print(subprocess.run("cd /mnt && df -h", shell=True, capture_output=True).stdout.decode()) | ||
|
||
|
||
with WorkflowTemplate( | ||
generate_name="volumes-", | ||
entrypoint="d", | ||
volumes=[ | ||
Volume(name="v1", mount_path="/mnt/v1", size="1Gi"), | ||
Volume(name="v2", mount_path="/mnt/v2", size="3Gi"), | ||
Volume(name="v3", mount_path="/mnt/v3", size="5Gi"), | ||
], | ||
) as w: | ||
with DAG(name="d"): | ||
foo(name="v1", arguments=Parameter(name="vol", value="v1")) | ||
foo(name="v2", arguments=Parameter(name="vol", value="v2")) | ||
foo(name="v3", arguments=Parameter(name="vol", value="v3")) |
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