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(ImageSpec): Ensure all APIErrors return a value #2408

Merged
merged 8 commits into from
May 13, 2024
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
3 changes: 2 additions & 1 deletion flytekit/image_spec/image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def exist(self) -> bool:
except APIError as e:
if e.response.status_code == 404:
return False
return True
except ImageNotFound:
return False
except Exception as e:
Expand All @@ -136,7 +137,7 @@ def exist(self) -> bool:
if response.status_code == 200:
return True

if response.status_code == 404:
if response.status_code == 404 and "not found" in str(response.content):
return False

click.secho(f"Failed to check if the image exists with error : {e}", fg="red")
Expand Down
10 changes: 5 additions & 5 deletions tests/flytekit/unit/core/image_spec/test_image_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_image_spec(mock_image_spec_builder):
packages=["pandas"],
apt_packages=["git"],
python_version="3.8",
registry="",
registry="localhost:30001",
base_image="cr.flyte.org/flyteorg/flytekit:py3.8-latest",
cuda="11.2.2",
cudnn="8",
Expand All @@ -37,7 +37,7 @@ def test_image_spec(mock_image_spec_builder):
assert image_spec.base_image == "cr.flyte.org/flyteorg/flytekit:py3.8-latest"
assert image_spec.packages == ["pandas", "numpy"]
assert image_spec.apt_packages == ["git", "wget"]
assert image_spec.registry == ""
assert image_spec.registry == "localhost:30001"
assert image_spec.requirements == REQUIREMENT_FILE
assert image_spec.registry_config == REGISTRY_CONFIG_FILE
assert image_spec.cuda == "11.2.2"
Expand All @@ -53,20 +53,20 @@ def test_image_spec(mock_image_spec_builder):

tag = calculate_hash_from_image_spec(image_spec)
assert "=" != tag[-1]
assert image_spec.image_name() == f"flytekit:{tag}"
assert image_spec.image_name() == f"localhost:30001/flytekit:{tag}"
ctx = context_manager.FlyteContext.current_context()
with context_manager.FlyteContextManager.with_context(
ctx.with_execution_state(ctx.execution_state.with_params(mode=ExecutionState.Mode.TASK_EXECUTION))
):
os.environ[_F_IMG_ID] = "flytekit:123"
os.environ[_F_IMG_ID] = "localhost:30001/flytekit:123"
assert image_spec.is_container() is False

ImageBuildEngine.register("dummy", mock_image_spec_builder)
ImageBuildEngine.build(image_spec)

assert "dummy" in ImageBuildEngine._REGISTRY
assert calculate_hash_from_image_spec(image_spec) == tag
assert image_spec.exist() is False
assert image_spec.exist() is True

# Remove the dummy builder, and build the image again
# The image has already been built, so it shouldn't fail.
Expand Down
Loading