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 handling of ImageConfig creation #983

Merged
merged 3 commits into from
Apr 28, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/upgrade_automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
with:
component: boilerplate
secrets:
FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }}
FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }}
7 changes: 6 additions & 1 deletion flytekit/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ def validate_image(_: typing.Any, param: str, values: tuple) -> ImageConfig:
return ImageConfig.create_from(default_image=default_image, other_images=images)

@classmethod
def create_from(cls, default_image: Image, other_images: typing.Optional[typing.List[Image]] = None) -> ImageConfig:
def create_from(
cls, default_image: Optional[Image], other_images: typing.Optional[typing.List[Image]] = None
) -> ImageConfig:
if default_image and not isinstance(default_image, Image):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a simple str too and then we do the conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add in a separate PR.

raise ValueError(f"Default image should be of type Image or None not {type(default_image)}")
all_images = [default_image] if default_image else []
if other_images:
all_images.extend(other_images)
Expand Down Expand Up @@ -263,6 +267,7 @@ def from_images(cls, default_image: str, m: typing.Optional[typing.Dict[str, str

:return:
"""
m = m or {}
def_img = Image.look_up_image_info("default", default_image) if default_image else None
other_images = [Image.look_up_image_info(k, tag=v, optional_tag=True) for k, v in m.items()]
return cls.create_from(def_img, other_images)
Expand Down
8 changes: 8 additions & 0 deletions tests/flytekit/unit/configuration/test_image_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ def test_not_version(mock_sys):
# Python version 2 not in enum
with pytest.raises(ValueError):
DefaultImages.default_image()


def test_image_create():
with pytest.raises(ValueError):
ImageConfig.create_from("ghcr.io/im/g:latest")

ic = ImageConfig.from_images("ghcr.io/im/g:latest")
assert ic.default_image.fqn == "ghcr.io/im/g"