Skip to content

Commit

Permalink
Fix ineffective GlobalConfig image settings in script (#538)
Browse files Browse the repository at this point in the history
Fixes image were not being applied in ContainerMixin and mixed in classes.

Signed-off-by: Pierre Brunelle <[email protected]>
Co-authored-by: Pierre Brunelle <[email protected]>
  • Loading branch information
pbrunelle and Pierre-Brunelle authored Mar 31, 2023
1 parent c2080f5 commit f2bf6e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
19 changes: 18 additions & 1 deletion docs/examples/workflows/global_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@

```python linenums="1"
from hera.shared import global_config
from hera.workflows import Container, Workflow
from hera.workflows import Container, Workflow, script

global_config.api_version = "argoproj.io/v0beta9000"
global_config.namespace = "argo-namespace"
global_config.service_account_name = "argo-account"
global_config.image = "image-say"


@script()
def say():
print("hello")


with Workflow(generate_name="global-config-", entrypoint="whalesay") as w:
whalesay = Container(image="docker/whalesay:latest", command=["cowsay"])
say()
```

=== "YAML"
Expand All @@ -35,5 +43,14 @@
command:
- cowsay
image: docker/whalesay:latest
- name: 'say'
script:
command: ['python']
image: 'image-say'
source: |
import os
import sys
sys.path.append(os.getcwd())
print("hello")
```

9 changes: 9 additions & 0 deletions examples/workflows/global-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ spec:
command:
- cowsay
image: docker/whalesay:latest
- name: 'say'
script:
command: ['python']
image: 'image-say'
source: |
import os
import sys
sys.path.append(os.getcwd())
print("hello")
10 changes: 9 additions & 1 deletion examples/workflows/global_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from hera.shared import global_config
from hera.workflows import Container, Workflow
from hera.workflows import Container, Workflow, script

global_config.api_version = "argoproj.io/v0beta9000"
global_config.namespace = "argo-namespace"
global_config.service_account_name = "argo-account"
global_config.image = "image-say"


@script()
def say():
print("hello")


with Workflow(generate_name="global-config-", entrypoint="whalesay") as w:
whalesay = Container(image="docker/whalesay:latest", command=["cowsay"])
say()
10 changes: 8 additions & 2 deletions src/hera/workflows/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import inspect
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, cast

from pydantic import root_validator
from pydantic import root_validator, validator

from hera.shared import global_config
from hera.shared._base_model import BaseMixin
Expand Down Expand Up @@ -124,7 +124,7 @@ def _add_sub(self, node: Any) -> Any:


class ContainerMixin(BaseMixin):
image: str = global_config.image
image: Optional[str] = None
image_pull_policy: Optional[Union[str, ImagePullPolicy]] = None

liveness_probe: Optional[Probe] = None
Expand All @@ -142,6 +142,12 @@ def _build_image_pull_policy(self) -> Optional[ImagePullPolicy]:
return self.image_pull_policy
return ImagePullPolicy[self.image_pull_policy.lower()]

@validator("image", pre=True, always=True)
def _set_image(cls, v):
if v is None:
return global_config.image
return v


class IOMixin(BaseMixin):
inputs: InputsT = None
Expand Down

0 comments on commit f2bf6e2

Please sign in to comment.