From 5437baa7011be02181d75be01abac98209ddd711 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:20:15 +0800 Subject: [PATCH 1/8] fix(ImageSpec): Ensure all APIErrors return a value --- flytekit/image_spec/image_spec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index b4772d1a92..a11f06f675 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -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: From 8922a5b5fafbdf184ee573c68f640f5314d18128 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:24:55 +0800 Subject: [PATCH 2/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index a11f06f675..9f87c464a0 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -121,7 +121,9 @@ def exist(self) -> bool: return True except APIError as e: if e.response.status_code == 404: + print("404") return False + print("test") return True except ImageNotFound: return False From ff56a6e4fe7e3a77e195f3d0a5b509e525bb6f9a Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:28:36 +0800 Subject: [PATCH 3/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index 9f87c464a0..93dc51d7f9 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -126,6 +126,7 @@ def exist(self) -> bool: print("test") return True except ImageNotFound: + print("ImageNotFound") return False except Exception as e: tag = calculate_hash_from_image_spec(self) From e868781f7e837fa007fd3e3b60d0db502aac0a20 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:35:07 +0800 Subject: [PATCH 4/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index 93dc51d7f9..766fc31741 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -112,6 +112,7 @@ def exist(self) -> bool: import docker from docker.errors import APIError, ImageNotFound + print("exist.................") try: client = docker.from_env() if self.registry: From e17ac2befda5012f69641bd95a349fc65145b658 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:37:19 +0800 Subject: [PATCH 5/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index 766fc31741..4c22def13f 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -142,6 +142,7 @@ def exist(self) -> bool: return True if response.status_code == 404: + print("sddddddddddddddddddddd") return False click.secho(f"Failed to check if the image exists with error : {e}", fg="red") From 285148f1189cd1b14503b50caf60ba63222272e9 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:52:13 +0800 Subject: [PATCH 6/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index 4c22def13f..a4c9212d68 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -141,8 +141,7 @@ def exist(self) -> bool: if response.status_code == 200: return True - if response.status_code == 404: - print("sddddddddddddddddddddd") + 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") From 7f4213d35e9da5aebc0fd10d859e263c97c02877 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 05:54:01 +0800 Subject: [PATCH 7/8] test Signed-off-by: Kevin Su --- flytekit/image_spec/image_spec.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/flytekit/image_spec/image_spec.py b/flytekit/image_spec/image_spec.py index a4c9212d68..1a055fce84 100644 --- a/flytekit/image_spec/image_spec.py +++ b/flytekit/image_spec/image_spec.py @@ -112,7 +112,6 @@ def exist(self) -> bool: import docker from docker.errors import APIError, ImageNotFound - print("exist.................") try: client = docker.from_env() if self.registry: @@ -122,12 +121,9 @@ def exist(self) -> bool: return True except APIError as e: if e.response.status_code == 404: - print("404") return False - print("test") return True except ImageNotFound: - print("ImageNotFound") return False except Exception as e: tag = calculate_hash_from_image_spec(self) From 702c8acba6c02ebf31978368a9ed18530a4c1823 Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Sat, 11 May 2024 06:18:24 +0800 Subject: [PATCH 8/8] fix test Signed-off-by: Kevin Su --- tests/flytekit/unit/core/image_spec/test_image_spec.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/flytekit/unit/core/image_spec/test_image_spec.py b/tests/flytekit/unit/core/image_spec/test_image_spec.py index 15b14f6687..4d204e11a0 100644 --- a/tests/flytekit/unit/core/image_spec/test_image_spec.py +++ b/tests/flytekit/unit/core/image_spec/test_image_spec.py @@ -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", @@ -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" @@ -53,12 +53,12 @@ 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) @@ -66,7 +66,7 @@ def test_image_spec(mock_image_spec_builder): 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.