Skip to content

Commit

Permalink
fix: add hibernation and deletion time in status
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Oct 4, 2024
1 parent 860c958 commit 64279f6
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions components/renku_data_services/notebooks/crs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Custom resource definition with proper names from the autogenerated code."""

from datetime import datetime
from datetime import UTC, datetime
from typing import Any, cast
from urllib.parse import urljoin, urlparse, urlunparse

from kubernetes.utils import parse_quantity
from kubernetes.utils import parse_duration, parse_quantity
from pydantic import BaseModel, Field, field_validator
from sanic.log import logger
from ulid import ULID
Expand All @@ -24,6 +24,7 @@
SecretRef,
Session,
State,
Status,
Storage,
TlsSecret,
)
Expand Down Expand Up @@ -190,6 +191,30 @@ def as_apispec(self) -> apispec.SessionResponse:
else:
state = apispec.State3.starting

will_hibernate_at: datetime | None = None
will_delete_at: datetime | None = None
match self.status, self.spec.culling:
case (
Status(idle=True, idleSince=idle_since),
Culling(maxIdleDuration=max_idle),
) if idle_since and max_idle:
will_hibernate_at = idle_since + parse_duration(max_idle)
case (
Status(state=State.Failed, failingSince=failing_since),
Culling(maxFailedDuration=max_failed),
) if failing_since and max_failed:
will_hibernate_at = failing_since + parse_duration(max_failed)
case (
Status(state=State.NotReady),
Culling(maxAge=max_age),
) if max_age and self.metadata.creationTimestamp:
will_hibernate_at = self.metadata.creationTimestamp + parse_duration(max_age)
case (
Status(state=State.Hibernated, hibernatedSince=hibernated_since),
Culling(maxHibernatedDuration=max_hibernated),
) if hibernated_since and max_hibernated:
will_delete_at = hibernated_since + parse_duration(max_hibernated)

return apispec.SessionResponse(
image=self.spec.session.image,
name=self.metadata.name,
Expand All @@ -205,6 +230,8 @@ def as_apispec(self) -> apispec.SessionResponse:
state=state,
ready_containers=ready_containers,
total_containers=total_containers,
will_hibernate_at=will_hibernate_at,
will_delete_at=will_delete_at,
),
url=url,
project_id=str(self.project_id),
Expand Down

0 comments on commit 64279f6

Please sign in to comment.