Skip to content

Commit e0c3e23

Browse files
authored
GH-7196: More lenient regex for container image templating (#3421)
Signed-off-by: Thomas Newton <thomas.w.newton@gmail.com>
1 parent c164f35 commit e0c3e23

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

flytekit/core/python_auto_container.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,7 @@ def get_registerable_container_image(img: Optional[Union[str, ImageSpec]], cfg:
489489
# fqn will access the fully qualified name of the image (e.g. registry/imagename:version -> registry/imagename)
490490
# version will access the version part of the image (e.g. registry/imagename:version -> version)
491491
# With empty attribute, it'll access the full image path (e.g. registry/imagename:version -> registry/imagename:version)
492-
_IMAGE_REPLACE_REGEX = re.compile(r"({{\s*\.image[s]?(?:\.([a-zA-Z0-9_]+))(?:\.([a-zA-Z0-9_]+))?\s*}})", re.IGNORECASE)
492+
_IMAGE_TEMPLATE_SUBSTRING_REGEX = r"(?:\.([a-zA-Z0-9_-]+))"
493+
_IMAGE_REPLACE_REGEX = re.compile(
494+
rf"({{{{\s*\.image[s]?{_IMAGE_TEMPLATE_SUBSTRING_REGEX}{_IMAGE_TEMPLATE_SUBSTRING_REGEX}?\s*}}}})", re.IGNORECASE
495+
)

tests/flytekit/unit/core/test_python_function_task.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ def test_container_image_conversion(mock_image_spec_builder):
4848
name="other3",
4949
fqn="xyz.com/other3",
5050
)
51-
cfg = ImageConfig(default_image=default_img, images=[default_img, other_img, other_img2, other_img3])
51+
other_img4 = Image(
52+
name="other-4",
53+
fqn="other4",
54+
tag="tag4"
55+
)
56+
other_img5 = Image(
57+
name="other_5",
58+
fqn="xyz.com/other5",
59+
tag="tag5"
60+
)
61+
cfg = ImageConfig(default_image=default_img, images=[default_img, other_img, other_img2, other_img3, other_img4, other_img5])
5262
assert get_registerable_container_image(None, cfg) == "xyz.com/abc:tag1"
5363
assert get_registerable_container_image("", cfg) == "xyz.com/abc:tag1"
5464
assert get_registerable_container_image("abc", cfg) == "abc"
@@ -72,6 +82,15 @@ def test_container_image_conversion(mock_image_spec_builder):
7282
get_registerable_container_image("{{.image.other3.fqn}}:{{.image.other3.version}}", cfg)
7383
== "xyz.com/other3:tag1"
7484
)
85+
assert (
86+
get_registerable_container_image("{{.image.other-4.fqn}}:{{.image.other-4.version}}", cfg)
87+
== "other4:tag4"
88+
)
89+
assert (
90+
get_registerable_container_image("{{.image.other_5.fqn}}:{{.image.other_5.version}}", cfg)
91+
== "xyz.com/other5:tag5"
92+
)
93+
7594
assert get_registerable_container_image("{{.image.other.fqn}}", cfg) == "xyz.com/other"
7695
# Works with images instead of just image
7796
assert get_registerable_container_image("{{.images.other.fqn}}", cfg) == "xyz.com/other"

0 commit comments

Comments
 (0)