Skip to content

Commit 558f88a

Browse files
authored
🐛 Started dynamic services do not take the correct Reservation (ITISFoundation#3047)
1 parent 775690f commit 558f88a

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

packages/models-library/src/models_library/aiodocker_api.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
from pydantic import Field, validator
44

5-
from .generated_models.docker_rest_api import ContainerSpec, ServiceSpec, TaskSpec
5+
from .generated_models.docker_rest_api import (
6+
ContainerSpec,
7+
ResourceObject,
8+
Resources1,
9+
ServiceSpec,
10+
TaskSpec,
11+
)
612
from .utils.converters import to_snake_case
713

814

@@ -26,11 +32,27 @@ def convert_list_to_dict(cls, v):
2632
return v
2733

2834

35+
class AioDockerResources1(Resources1):
36+
# NOTE: The Docker REST API documentation is wrong!!!
37+
# Do not set that back to singular Reservation.
38+
Reservation: Optional[ResourceObject] = Field(
39+
None, description="Define resources reservation.", alias="Reservations"
40+
)
41+
42+
class Config(Resources1.Config):
43+
allow_population_by_field_name = True
44+
45+
2946
class AioDockerTaskSpec(TaskSpec):
3047
ContainerSpec: Optional[AioDockerContainerSpec] = Field(
3148
None,
3249
)
3350

51+
Resources: Optional[AioDockerResources1] = Field(
52+
None,
53+
description="Resource requirements which apply to each individual container created\nas part of the service.\n",
54+
)
55+
3456

3557
class AioDockerServiceSpec(ServiceSpec):
3658

services/catalog/src/simcore_service_catalog/api/routes/services_resources.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
logger = logging.getLogger(__name__)
2727

2828

29-
# TODO: Reservation and not Reservations https://github.com/ITISFoundation/osparc-simcore/issues/3044
30-
31-
3229
def _parse_generic_resource(
3330
generic_resources: list[Any], service_resources: ServiceResources
3431
) -> None:

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_service_specs/settings.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ def inject_settings_to_create_service_params(
100100
"NanoCPUs"
101101
] = param.value["cpu_reservation"]
102102
# REST-API compatible
103-
if (
104-
"Limits" in param.value
105-
or "Reservation" in param.value
106-
or "Reservations" in param.value
107-
):
108-
# NOTE: Reservations is incorrect. It's Reservation but we keep it for backwards compatibility
103+
if "Limits" in param.value or "Reservations" in param.value:
104+
# NOTE: The Docker REST API reads Reservation when actually it's Reservations
109105
create_service_params["task_template"]["Resources"].update(param.value)
110106

111107
# publishing port on the ingress network.
@@ -157,27 +153,6 @@ def inject_settings_to_create_service_params(
157153
create_service_params["task_template"]["Resources"]["Limits"]["MemoryBytes"]
158154
)
159155

160-
_clean_reservation_field(create_service_params)
161-
162-
163-
def _clean_reservation_field(service_spec: dict[str, Any]) -> None:
164-
WRONG_FIELD = "Reservations"
165-
RIGHT_FIELD = "Reservation"
166-
if WRONG_FIELD not in service_spec["task_template"].get("Resources", {}):
167-
return
168-
# NOTE: in old services, there is a typo in the field. There is no s in Reservation in
169-
# the Docker API (see https://docs.docker.com/engine/api/v1.41/#operation/ServiceCreate)
170-
new_reservation = service_spec["task_template"]["Resources"][WRONG_FIELD]
171-
if (
172-
current_reservation := service_spec["task_template"]
173-
.get("Resources", {})
174-
.get(RIGHT_FIELD)
175-
):
176-
new_reservation = current_reservation | new_reservation
177-
178-
service_spec["task_template"]["Resources"][RIGHT_FIELD] = new_reservation
179-
service_spec["task_template"]["Resources"].pop(WRONG_FIELD)
180-
181156

182157
def _assemble_key(service_key: str, service_tag: str) -> str:
183158
return f"{service_key}:{service_tag}"

services/director-v2/tests/unit/test_modules_dynamic_sidecar_docker_service_specs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def expected_dynamic_sidecar_spec() -> dict[str, Any]:
271271
"Placement": {"Constraints": ["node.platform.os == linux"]},
272272
"Resources": {
273273
"Limits": {"MemoryBytes": 8589934592, "NanoCPUs": 4000000000},
274-
"Reservation": {
274+
"Reservations": {
275275
"GenericResources": [
276276
{"DiscreteResourceSpec": {"Kind": "VRAM", "Value": 1}}
277277
],

0 commit comments

Comments
 (0)