Skip to content

Commit

Permalink
Save all process configuration as parameters, not just input values
Browse files Browse the repository at this point in the history
  • Loading branch information
totycro committed Jul 29, 2024
1 parent cc0ebf4 commit d7f6090
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 2 additions & 9 deletions pygeoapi_kubernetes_papermill/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down
12 changes: 7 additions & 5 deletions tests/test_notebook_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d7f6090

Please sign in to comment.