Skip to content

Commit cb6857d

Browse files
committed
squashme: address comments
1 parent 638dcd3 commit cb6857d

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

components/renku_data_services/notebooks/core_sessions.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,13 @@ def resources_patch_from_resource_class(resource_class: ResourceClass) -> Resour
469469
"""Convert the resource class to a k8s resources spec."""
470470
gpu_name = GpuKind.NVIDIA.value + "/gpu"
471471
resources = resources_from_resource_class(resource_class)
472-
requests: Mapping[str, Requests | RequestsStr | ResetType] | ResetType
473-
limits: Mapping[str, Limits | LimitsStr | ResetType] | ResetType
472+
requests: Mapping[str, Requests | RequestsStr | ResetType] | ResetType | None = None
473+
limits: Mapping[str, Limits | LimitsStr | ResetType] | ResetType | None = None
474474
defaul_requests = {"memory": RESET, "cpu": RESET, gpu_name: RESET}
475475
default_limits = {"memory": RESET, "cpu": RESET, gpu_name: RESET}
476-
if resources.requests:
476+
if resources.requests is not None:
477477
requests = RESET if len(resources.requests.keys()) == 0 else {**defaul_requests, **resources.requests}
478-
if resources.limits:
478+
if resources.limits is not None:
479479
limits = RESET if len(resources.limits.keys()) == 0 else {**default_limits, **resources.limits}
480480
return ResourcesPatch(requests=requests, limits=limits)
481481

@@ -1073,17 +1073,11 @@ async def patch_session(
10731073
)
10741074
)
10751075
rp = await rp_repo.get_resource_pool_from_class(user, body.resource_class_id)
1076-
try:
1077-
old_rp = await rp_repo.get_resource_pool_from_class(user, session.resource_class_id())
1078-
except (errors.MissingResourceError, errors.UnauthorizedError, errors.ForbiddenError):
1079-
old_rp = None
10801076
rc = rp.get_resource_class(body.resource_class_id)
10811077
if not rc:
10821078
raise errors.MissingResourceError(
10831079
message=f"The resource class you requested with ID {body.resource_class_id} does not exist"
10841080
)
1085-
if old_rp is not None and rp.cluster != old_rp.cluster:
1086-
raise errors.ValidationError(message="Changing resource pools with different clusters is not allowed.")
10871081
if not patch.metadata:
10881082
patch.metadata = AmaltheaSessionV1Alpha1MetadataPatch()
10891083
# Patch the resource pool and class ID in the annotations

components/renku_data_services/notebooks/crs.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def resource_class_id(self) -> int:
154154
return i
155155

156156

157-
class Culling(_ASCulling):
157+
class CullingDurationParsingMixin(BaseCRD):
158158
"""Amalthea session culling configuration."""
159159

160160
@field_serializer("*", mode="wrap")
@@ -171,6 +171,12 @@ def __deserialize_duration(cls, val: Any, handler: Any) -> Any:
171171
return handler(val)
172172

173173

174+
class Culling(_ASCulling, CullingDurationParsingMixin):
175+
"""Amalthea session culling configuration."""
176+
177+
pass
178+
179+
174180
class Requests(_Requests):
175181
"""Resource requests of type integer."""
176182

@@ -409,14 +415,14 @@ class AffinityPatch(BaseCRD):
409415
podAntiAffinity: PodAntiAffinity | ResetType | None = None
410416

411417

412-
class CullingPatch(Culling):
418+
class CullingPatch(CullingDurationParsingMixin):
413419
"""Patch for the culling durations of a session."""
414420

415-
maxAge: timedelta | ResetType | None = None # type:ignore[assignment]
416-
maxFailedDuration: timedelta | ResetType | None = None # type:ignore[assignment]
417-
maxHibernatedDuration: timedelta | ResetType | None = None # type:ignore[assignment]
418-
maxIdleDuration: timedelta | ResetType | None = None # type:ignore[assignment]
419-
maxStartingDuration: timedelta | ResetType | None = None # type:ignore[assignment]
421+
maxAge: timedelta | ResetType | None = None
422+
maxFailedDuration: timedelta | ResetType | None = None
423+
maxHibernatedDuration: timedelta | ResetType | None = None
424+
maxIdleDuration: timedelta | ResetType | None = None
425+
maxStartingDuration: timedelta | ResetType | None = None
420426

421427

422428
class AmaltheaSessionV1Alpha1SpecPatch(BaseCRD):

test/bases/renku_data_services/data_api/test_notebooks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ async def test_patch_server(
258258

259259
assert res.status_code == expected_status_code, res.text
260260
if expected_status_code == 200 and patch == {"state": "hibernated"}:
261+
# NOTE: The status of amalthea needs a few seconds to update and show up in the response
262+
await asyncio.sleep(2)
263+
_, res = await sanic_client.get(f"/api/data/sessions/{server_name}", headers=authenticated_user_headers)
264+
assert res.status_code == 200
261265
assert res.json["status"]["state"] == "hibernated"
262266
if expected_status_code == 200 and "resource_class_id" in patch:
263267
assert res.json["resource_class_id"] == patch["resource_class_id"]

0 commit comments

Comments
 (0)