Skip to content

Commit

Permalink
Show executed notebook as part of parameters
Browse files Browse the repository at this point in the history
This now mixes different layers, but it's only for information and seems
convenient.
  • Loading branch information
totycro committed Nov 23, 2023
1 parent 18273d2 commit 6a76961
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pygeoapi_kubernetes_papermill/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {}
),
)
)
Expand Down
1 change: 1 addition & 0 deletions pygeoapi_kubernetes_papermill/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_kubernetes_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 6a76961

Please sign in to comment.