diff --git a/pygeoapi_kubernetes_papermill/kubernetes.py b/pygeoapi_kubernetes_papermill/kubernetes.py index fa46ac0..d01a8f4 100644 --- a/pygeoapi_kubernetes_papermill/kubernetes.py +++ b/pygeoapi_kubernetes_papermill/kubernetes.py @@ -59,8 +59,8 @@ class KubernetesProcessor(BaseProcessor): @dataclass(frozen=True) class JobPodSpec: pod_spec: k8s_client.V1PodSpec - extra_annotations: Dict - extra_labels: Dict + extra_annotations: Dict[str, str] + extra_labels: Dict[str, str] def create_job_pod_spec( self, @@ -414,12 +414,19 @@ def job_from_k8s(job: k8s_client.V1Job, message: Optional[str]) -> JobDict: for orig_key, v in annotations.items() if (parsed_key := parse_annotation_key(orig_key)) } + executed_notebook = metadata_from_annotation.get("executed-notebook") try: metadata_from_annotation["parameters"] = json.dumps( hide_secret_values( json.loads( metadata_from_annotation.get("parameters", "{}"), + ) + # executed notebook is not part of params, but show in UI + | ( + {"executed-notebook": executed_notebook} + if executed_notebook + else {} ), ) ) diff --git a/pygeoapi_kubernetes_papermill/notebook.py b/pygeoapi_kubernetes_papermill/notebook.py index ac7ba12..609dd83 100644 --- a/pygeoapi_kubernetes_papermill/notebook.py +++ b/pygeoapi_kubernetes_papermill/notebook.py @@ -353,6 +353,7 @@ def create_job_pod_spec( 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]} diff --git a/tests/test_kubernetes_manager.py b/tests/test_kubernetes_manager.py index 687f6cf..3624d4c 100644 --- a/tests/test_kubernetes_manager.py +++ b/tests/test_kubernetes_manager.py @@ -284,3 +284,15 @@ def test_secret_job_annotation_parameters_are_hidden(): parameters = json.loads(job_dict["parameters"]) assert parameters["foo"] == "bar" assert parameters["foo-secret"] == "*" + + +def test_job_params_contain_executed_notebook(): + job = k8s_client.V1Job( + metadata=k8s_client.V1ObjectMeta( + annotations={"pygeoapi.io/executed-notebook": "extra/nb.ipynb"} + ), + status=k8s_client.V1JobStatus(), + ) + job_dict = job_from_k8s(job, message="") + parameters = json.loads(job_dict["parameters"]) + assert parameters["executed-notebook"] == "extra/nb.ipynb"