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

fix image pull policy validation error #586

Merged
merged 3 commits into from
Apr 20, 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
48 changes: 48 additions & 0 deletions docs/examples/workflows/script_with_image_pull_policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Script With Image Pull Policy






=== "Hera"

```python linenums="1"
from hera.workflows import Workflow, script
from hera.workflows.models import ImagePullPolicy


@script(image_pull_policy=ImagePullPolicy.always)
def task_with_image_pull_policy():
print("ok")


with Workflow(generate_name="script-with-image-pull-policy-", entrypoint="task-with-image-pull-policy") as w:
task_with_image_pull_policy()
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: script-with-image-pull-policy-
spec:
entrypoint: task-with-image-pull-policy
templates:
- name: task-with-image-pull-policy
script:
command:
- python
image: python:3.8
imagePullPolicy: Always
source: 'import os

import sys

sys.path.append(os.getcwd())

print(''ok'')'
```

20 changes: 20 additions & 0 deletions examples/workflows/script-with-image-pull-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: script-with-image-pull-policy-
spec:
entrypoint: task-with-image-pull-policy
templates:
- name: task-with-image-pull-policy
script:
command:
- python
image: python:3.8
imagePullPolicy: Always
source: 'import os

import sys

sys.path.append(os.getcwd())

print(''ok'')'
11 changes: 11 additions & 0 deletions examples/workflows/script_with_image_pull_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from hera.workflows import Workflow, script
from hera.workflows.models import ImagePullPolicy


@script(image_pull_policy=ImagePullPolicy.always)
def task_with_image_pull_policy():
print("ok")


with Workflow(generate_name="script-with-image-pull-policy-", entrypoint="task-with-image-pull-policy") as w:
task_with_image_pull_policy()
10 changes: 6 additions & 4 deletions src/hera/workflows/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ class ContainerMixin(BaseMixin):
termination_message_policy: Optional[TerminationMessagePolicy] = None
tty: Optional[bool] = None

def _build_image_pull_policy(self) -> Optional[ImagePullPolicy]:
if self.image_pull_policy is None or isinstance(self.image_pull_policy, ImagePullPolicy):
return self.image_pull_policy
return ImagePullPolicy[self.image_pull_policy.lower()]
def _build_image_pull_policy(self) -> Optional[str]:
if self.image_pull_policy is None:
return None
elif isinstance(self.image_pull_policy, ImagePullPolicy):
return self.image_pull_policy.value
return ImagePullPolicy[self.image_pull_policy.lower()].value

@validator("image", pre=True, always=True)
def _set_image(cls, v):
Expand Down