From eeb66b3844175feef1882b45f7c643cb3ac6e9ee Mon Sep 17 00:00:00 2001 From: Tim Bauer <30375389+bimtauer@users.noreply.github.com> Date: Mon, 18 Oct 2021 23:08:29 +0200 Subject: [PATCH] Fix: Make sure default image can be found (#698) Signed-off-by: Tim Bauer --- flytekit/core/context_manager.py | 3 ++- .../unit/core/test_python_auto_container.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/flytekit/unit/core/test_python_auto_container.py diff --git a/flytekit/core/context_manager.py b/flytekit/core/context_manager.py index 3e4c77af6d..627cf3ea11 100644 --- a/flytekit/core/context_manager.py +++ b/flytekit/core/context_manager.py @@ -92,7 +92,8 @@ def find_image(self, name) -> Optional[Image]: """ Return an image, by name, if it exists. """ - for i in self.images: + lookup_images = self.images + [self.default_image] if self.images else [self.default_image] + for i in lookup_images: if i.name == name: return i return None diff --git a/tests/flytekit/unit/core/test_python_auto_container.py b/tests/flytekit/unit/core/test_python_auto_container.py new file mode 100644 index 0000000000..edd3140554 --- /dev/null +++ b/tests/flytekit/unit/core/test_python_auto_container.py @@ -0,0 +1,16 @@ +import pytest + +from flytekit.core.context_manager import Image, ImageConfig +from flytekit.core.python_auto_container import get_registerable_container_image + + +@pytest.fixture +def default_image_config(): + default_image = Image(name="default", fqn="docker.io/xyz", tag="some-git-hash") + return ImageConfig(default_image=default_image) + + +def test_image_name_interpolation(default_image_config): + img_to_interpolate = "{{.image.default.fqn}}:{{.image.default.version}}-special" + img = get_registerable_container_image(img=img_to_interpolate, cfg=default_image_config) + assert img == "docker.io/xyz:some-git-hash-special"