Skip to content

Commit 2f9197d

Browse files
authored
fix: delete anonymous sessions right after pausing (#907)
1 parent b53466c commit 2f9197d

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

components/renku_data_services/notebooks/blueprints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def _handler(
432432
extraContainers=extra_containers,
433433
initContainers=extra_init_containers,
434434
extraVolumes=extra_volumes,
435-
culling=get_culling(resource_pool, self.nb_config),
435+
culling=get_culling(user, resource_pool, self.nb_config),
436436
authentication=Authentication(
437437
enabled=True,
438438
type=AuthenticationType.oauth2proxy

components/renku_data_services/notebooks/core_sessions.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,20 @@ async def repositories_from_session(
435435
return repositories_from_project(project, git_providers)
436436

437437

438-
def get_culling(resource_pool: ResourcePool, nb_config: NotebooksConfig) -> Culling:
438+
def get_culling(
439+
user: AuthenticatedAPIUser | AnonymousAPIUser, resource_pool: ResourcePool, nb_config: NotebooksConfig
440+
) -> Culling:
439441
"""Create the culling specification for an AmaltheaSession."""
440442
idle_threshold_seconds = resource_pool.idle_threshold or nb_config.sessions.culling.registered.idle_seconds
441-
hibernation_threshold_seconds = (
442-
resource_pool.hibernation_threshold or nb_config.sessions.culling.registered.hibernated_seconds
443-
)
443+
if user.is_anonymous:
444+
# NOTE: Anonymous sessions should not be hibernated at all, but there is no such option in Amalthea
445+
# So in this case we set a very low hibernation threshold so the session is deleted quickly after
446+
# it is hibernated.
447+
hibernation_threshold_seconds = 1
448+
else:
449+
hibernation_threshold_seconds = (
450+
resource_pool.hibernation_threshold or nb_config.sessions.culling.registered.hibernated_seconds
451+
)
444452
return Culling(
445453
maxAge=format_duration(timedelta(seconds=nb_config.sessions.culling.registered.max_age_seconds)),
446454
maxFailedDuration=format_duration(timedelta(seconds=nb_config.sessions.culling.registered.failed_seconds)),
@@ -529,7 +537,7 @@ async def patch_session(
529537
patch.spec.affinity = node_affinity_from_resource_class(rc, nb_config.sessions.affinity_model)
530538
# Priority class (if a quota is being used)
531539
patch.spec.priorityClassName = rc.quota
532-
patch.spec.culling = get_culling(rp, nb_config)
540+
patch.spec.culling = get_culling(user, rp, nb_config)
533541

534542
# If the session is being hibernated we do not need to patch anything else that is
535543
# not specifically called for in the request body, we can refresh things when the user resumes.

0 commit comments

Comments
 (0)