-
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.
Fix incorrect aggregation of volume mount and dynamic volumes created…
… via Hera (#875) **Pull Request Checklist** - [x] Fixes #<!--issue number goes here--> - [x] Tests added - [x] Documentation/examples added - [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR title **Description of PR** Hera supports building dynamic volumes via the `Volume` object. That creates PVCs + PVs dynamically. Users have the liberty to mount these volumes wherever they want. However, if users have a volume mount _already_, then the dynamic volumes are not combined with mounts correctly. That happens because of the incorrect conditions inside of `build_volume_mounts`. This PR fixes that Signed-off-by: Flaviu Vadan <flaviuvadan@gmail.com>
- Loading branch information
1 parent
936d1b3
commit c2ef94b
Showing
4 changed files
with
130 additions
and
8 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,69 @@ | ||
# Volume Mount | ||
|
||
|
||
|
||
This example showcases how to create a volume at a workflow level and use it in a container via a mount. | ||
|
||
|
||
=== "Hera" | ||
|
||
```python linenums="1" | ||
from hera.workflows import Container, SecretVolume, Steps, Volume, Workflow | ||
from hera.workflows.models import VolumeMount | ||
|
||
with Workflow( | ||
generate_name="test-", | ||
volumes=[SecretVolume(name="service-account-credential", secret_name="service-account-credential")], | ||
entrypoint="test", | ||
) as w: | ||
v_tmp_pod = Volume( | ||
name="tmp-pod", | ||
size="100Mi", | ||
mount_path="/tmp/pod", | ||
) | ||
init_container_example = Container( | ||
name="git-sync", | ||
volume_mounts=[VolumeMount(name="service-account-credential", mount_path="/secrets")], | ||
volumes=[v_tmp_pod], | ||
) | ||
with Steps(name="test") as s: | ||
init_container_example() | ||
``` | ||
|
||
=== "YAML" | ||
|
||
```yaml linenums="1" | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: test- | ||
spec: | ||
entrypoint: test | ||
templates: | ||
- container: | ||
image: python:3.8 | ||
volumeMounts: | ||
- mountPath: /secrets | ||
name: service-account-credential | ||
- mountPath: /tmp/pod | ||
name: tmp-pod | ||
name: git-sync | ||
- name: test | ||
steps: | ||
- - name: git-sync | ||
template: git-sync | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: tmp-pod | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 100Mi | ||
volumes: | ||
- name: service-account-credential | ||
secret: | ||
secretName: service-account-credential | ||
``` | ||
|
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,32 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: test- | ||
spec: | ||
entrypoint: test | ||
templates: | ||
- container: | ||
image: python:3.8 | ||
volumeMounts: | ||
- mountPath: /secrets | ||
name: service-account-credential | ||
- mountPath: /tmp/pod | ||
name: tmp-pod | ||
name: git-sync | ||
- name: test | ||
steps: | ||
- - name: git-sync | ||
template: git-sync | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: tmp-pod | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 100Mi | ||
volumes: | ||
- name: service-account-credential | ||
secret: | ||
secretName: service-account-credential |
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,21 @@ | ||
"""This example showcases how to create a volume at a workflow level and use it in a container via a mount.""" | ||
from hera.workflows import Container, SecretVolume, Steps, Volume, Workflow | ||
from hera.workflows.models import VolumeMount | ||
|
||
with Workflow( | ||
generate_name="test-", | ||
volumes=[SecretVolume(name="service-account-credential", secret_name="service-account-credential")], | ||
entrypoint="test", | ||
) as w: | ||
v_tmp_pod = Volume( | ||
name="tmp-pod", | ||
size="100Mi", | ||
mount_path="/tmp/pod", | ||
) | ||
init_container_example = Container( | ||
name="git-sync", | ||
volume_mounts=[VolumeMount(name="service-account-credential", mount_path="/secrets")], | ||
volumes=[v_tmp_pod], | ||
) | ||
with Steps(name="test") as s: | ||
init_container_example() |
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