From 926a3a66d158eaa58aaa9c6afb53b77c80b6898c Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:05:22 +0100 Subject: [PATCH] =?UTF-8?q?[CDF-23535]=20=F0=9F=91=B7=20Redeploy=20issue?= =?UTF-8?q?=20index=20url=20(#1292)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tests: extended example * fix: not redeploy when setting indexUrl and extraIndexUrls * build: changelog * tests: regen --- CHANGELOG.cdf-tk.md | 6 ++++++ .../_resource_loaders/function_loaders.py | 4 ++++ .../functions/first.function.yaml | 3 ++- .../test_loaders/test_function_loader.py | 21 +++++++++++++++++++ .../complete_org.yaml | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.cdf-tk.md b/CHANGELOG.cdf-tk.md index f4acbd58b..df841b0fd 100644 --- a/CHANGELOG.cdf-tk.md +++ b/CHANGELOG.cdf-tk.md @@ -15,6 +15,12 @@ Changes are grouped as follows: - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## TBD + +### Fixed + +- Functions are no longer always redeployed if `indexUrl` or `extraIndexUrls` are set in the `Function` resource. + ## [0.3.21] - 2024-12-11 ### Fixed diff --git a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/function_loaders.py b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/function_loaders.py index c1b6575f3..69fbcb87b 100644 --- a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/function_loaders.py +++ b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/function_loaders.py @@ -180,6 +180,10 @@ def _are_equal( local_dumped["metadata"][self._MetadataKey.secret_hash] = calculate_secure_hash(local_dumped["secrets"]) local_dumped["secrets"] = {k: "***" for k in local_dumped["secrets"]} + # Only in write (request) format of the function + local_dumped.pop("indexUrl", None) + local_dumped.pop("extraIndexUrls", None) + return self._return_are_equal(local_dumped, cdf_dumped, return_dumped) def _is_activated(self, action: str) -> bool: diff --git a/tests/data/complete_org/modules/my_example_module/functions/first.function.yaml b/tests/data/complete_org/modules/my_example_module/functions/first.function.yaml index d2f267a72..fcd7d0a55 100644 --- a/tests/data/complete_org/modules/my_example_module/functions/first.function.yaml +++ b/tests/data/complete_org/modules/my_example_module/functions/first.function.yaml @@ -19,4 +19,5 @@ runtime: 'py311' functionPath: './src/handler.py' # Data set id for the zip file with the code that is uploaded. - dataSetExternalId: 'ds_timeseries_{{example_variable}}' \ No newline at end of file + dataSetExternalId: 'ds_timeseries_{{example_variable}}' + indexUrl: https://pypi.org/simple \ No newline at end of file diff --git a/tests/test_unit/test_cdf_tk/test_loaders/test_function_loader.py b/tests/test_unit/test_cdf_tk/test_loaders/test_function_loader.py index 835347b05..5e393fc67 100644 --- a/tests/test_unit/test_cdf_tk/test_loaders/test_function_loader.py +++ b/tests/test_unit/test_cdf_tk/test_loaders/test_function_loader.py @@ -70,3 +70,24 @@ def test_are_equals_secret_changing(self, cdf_tool_mock: CDFToolConfig, tmp_path "secret1": "value1", "secret2": "value2", }, "Original object should not be modified" + + def test_are_equals_index_url_set(self, cdf_tool_mock: CDFToolConfig, tmp_path: Path) -> None: + local_function = FunctionWrite( + name="my_function", + file_id=123, + external_id="my_function", + index_url="http://my-index-url", + ) + cdf_function = Function( + name="my_function", + file_id=123, + external_id="my_function", + metadata={ + FunctionLoader._MetadataKey.function_hash: calculate_directory_hash(tmp_path / "my_function"), + }, + ) + loader = FunctionLoader.create_loader(cdf_tool_mock, tmp_path) + + are_equal = loader.are_equal(local_function, cdf_function, return_dumped=False) + + assert are_equal is True diff --git a/tests/test_unit/test_cli/test_build_deploy_snapshots/complete_org.yaml b/tests/test_unit/test_cli/test_build_deploy_snapshots/complete_org.yaml index f216bfa9e..7cb8f63e4 100644 --- a/tests/test_unit/test_cli/test_build_deploy_snapshots/complete_org.yaml +++ b/tests/test_unit/test_cli/test_build_deploy_snapshots/complete_org.yaml @@ -178,6 +178,7 @@ Function: externalId: fn_first_function fileId: -1 functionPath: ./src/handler.py + indexUrl: https://pypi.org/simple metadata: cdf-toolkit-function-hash: a63720560f48030aaf994e92b02b1de1932514aa79b3115ced9d65fba8440aff cdf-toolkit-secret-hash: d218376a8813e2bb96b70b9f3df07157b0b58f18f3667c64e500032095f4f2cb0f1679ed7034189009131ce2e77cc363d840b478d94d8525cad7d9830a78e129