From 68a20fce457be030d641789adede0337eaa68902 Mon Sep 17 00:00:00 2001 From: sanderegg <35365065+sanderegg@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:13:12 +0200 Subject: [PATCH] needs separation of PR concerns --- .../src/models_library/docker.py | 30 ++++++++++++++++--- packages/models-library/tests/test_docker.py | 16 ++++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/models-library/src/models_library/docker.py b/packages/models-library/src/models_library/docker.py index 85e14f8abae2..ec7ff863ef44 100644 --- a/packages/models-library/src/models_library/docker.py +++ b/packages/models-library/src/models_library/docker.py @@ -35,18 +35,18 @@ class SimcoreServiceDockerLabelKeys(BaseModel): project_id: ProjectID = Field(..., alias="study_id") node_id: NodeID = Field(..., alias="uuid") - product_name: ProductName - simcore_user_agent: str + product_name: ProductName = "osparc" + simcore_user_agent: str = "undefined" # None is for backwards compatibility, can be removed in a few sprints memory_limit: ByteSize | None cpu_limit: float | None - def to_docker_labels(self) -> dict[str, str]: + def to_docker_labels(self) -> dict[DockerLabelKey, str]: """returns a dictionary of strings as required by docker""" std_export = self.dict(by_alias=True) return { - f"{_SIMCORE_CONTAINER_PREFIX}{k.replace('_', '-')}": f"{v}" + DockerLabelKey(f"{_SIMCORE_CONTAINER_PREFIX}{k.replace('_', '-')}"): f"{v}" for k, v in sorted(std_export.items()) } @@ -59,3 +59,25 @@ def from_docker_task(cls, docker_task: Task) -> "SimcoreServiceDockerLabelKeys": class Config: allow_population_by_field_name = True + schema_extra = { + "examples": [ + # legacy with no limits (a.k.a all dynamic services) + { + "uuid": "1f963626-66e1-43f1-a777-33955c08b909", + "study_id": "29f393fc-1410-47b3-b4b9-61dfce21a2a6", + "user_id": "5", + "product_name": "osparc", + "simcore_user_agent": "puppeteer", + }, + # modern both dynamic-sidecar services and computational services + { + "io.simcore.container.node-id": "1f963626-66e1-43f1-a777-33955c08b909", + "io.simcore.container.project-id": "29f393fc-1410-47b3-b4b9-61dfce21a2a6", + "io.simcore.container.user-id": "5", + "io.simcore.container.product-name": "osparc", + "io.simcore.container.simcore-user-agent": "puppeteer", + "io.simcore.container.memory-limit": "1073741824", + "io.simcore.container.cpu-limit": "2.4", + }, + ] + } diff --git a/packages/models-library/tests/test_docker.py b/packages/models-library/tests/test_docker.py index 066502c03a07..8dc5ead5fb7a 100644 --- a/packages/models-library/tests/test_docker.py +++ b/packages/models-library/tests/test_docker.py @@ -114,17 +114,27 @@ def test_docker_generic_tag(image_name: str, valid: bool): "project_id": _faker.uuid4(), "node_id": _faker.uuid4(), }, - id="parse_existing_service_labels", + id="parse_existing_service_labels-and-legacy", ), pytest.param( { "user_id": _faker.pyint(), "project_id": _faker.uuid4(), "node_id": _faker.uuid4(), - "product": "test_p", + "product_name": "test_p", "simcore_user_agent": "a-test-puppet", }, - id="parse_new_service_labels", + id="parse_new_service_labels-soon-to-removed", + ), + pytest.param( + { + "io.simcore.container.user_id": _faker.pyint(), + "io.simcore.container.project_id": _faker.uuid4(), + "io.simcore.container.node_id": _faker.uuid4(), + "io.simcore.container.product-name": "test_p", + "io.simcore.container.simcore_user_agent": "a-test-puppet", + }, + id="labels following docker rules", ), ], )