From d7f6090c47316d898996d75cdf2255450ea62eaa Mon Sep 17 00:00:00 2001 From: Bernhard Mallinger Date: Mon, 29 Jul 2024 11:51:23 +0200 Subject: [PATCH] Save all process configuration as parameters, not just input values --- CHANGELOG.md | 3 +++ pygeoapi_kubernetes_papermill/notebook.py | 11 ++--------- tests/test_notebook_processor.py | 12 +++++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e70eda..7043525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.3.0 +* Save all process configuration as parameters, not just input values + ## 1.2.7 * Add image pull secret for image processor diff --git a/pygeoapi_kubernetes_papermill/notebook.py b/pygeoapi_kubernetes_papermill/notebook.py index 44e43f5..58feeb8 100644 --- a/pygeoapi_kubernetes_papermill/notebook.py +++ b/pygeoapi_kubernetes_papermill/notebook.py @@ -44,7 +44,6 @@ import scrapbook.scraps from typing import Iterable, Optional, Any from typed_json_dataclass import TypedJsonMixin -import yaml from kubernetes import client as k8s_client @@ -336,18 +335,12 @@ def create_job_pod_spec( ), env_from=extra_config.env_from, ) - # json is much cheaper to parse, and we accept both b64-yaml and - # json as input, so save as json - parameters_str = b64decode(requested.parameters.encode()).decode() extra_annotations = { "result-notebook": str(output_notebook), "executed-notebook": str(requested.notebook), - } | ( # save parameters but make sure the string is not too long - {"parameters": json.dumps(yaml.safe_load(parameters_str))[:8000]} - if requested.parameters - else {} - ) + "parameters": json.dumps(data)[:8000], + } return KubernetesProcessor.JobPodSpec( pod_spec=k8s_client.V1PodSpec( diff --git a/tests/test_notebook_processor.py b/tests/test_notebook_processor.py index 668e89a..9c8f93b 100644 --- a/tests/test_notebook_processor.py +++ b/tests/test_notebook_processor.py @@ -107,7 +107,7 @@ def papermill_gpu_processor() -> PapermillNotebookKubernetesProcessor: @pytest.fixture() def create_pod_kwargs() -> Dict: return { - "data": {"notebook": "a.ipynb", "parameters": ""}, + "data": {"notebook": "a.ipynb"}, "job_name": "my-job", } @@ -146,12 +146,14 @@ def test_json_params_are_b64_encoded(papermill_processor, create_pod_kwargs_with ) -def test_yaml_parameters_are_saved_as_json(papermill_processor, create_pod_kwargs_with): - payload = b64encode(b"a: 3").decode() +def test_execution_parameters_are_saved(papermill_processor, create_pod_kwargs_with): job_pod_spec = papermill_processor.create_job_pod_spec( - **create_pod_kwargs_with({"parameters": payload}) + **create_pod_kwargs_with({"parameters_json": {"a": 3}}) ) - assert job_pod_spec.extra_annotations["parameters"] == '{"a": 3}' + assert json.loads(job_pod_spec.extra_annotations["parameters"]) == { + "notebook": "a.ipynb", + "parameters_json": {"a": 3}, + } def test_custom_output_file_overwrites_default(