Skip to content

Commit d3c9e42

Browse files
authored
chore: Pass renku annotations to amalthea session spec (#1206)
* Generate code for new amalthea version * Pass annotations and labels to amalthea spec template
1 parent 75b4116 commit d3c9e42

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
AMALTHEA_JS_VERSION ?= 0.22.0
2-
AMALTHEA_SESSIONS_VERSION ?= 0.22.0
1+
AMALTHEA_SESSIONS_VERSION ?= 0.25.0
32
COMMON_CODEGEN_PARAMS := \
43
--output-model-type pydantic_v2.BaseModel \
54
--use-double-quotes \
@@ -106,14 +105,12 @@ k3d_cluster: ## Creates a k3d cluster for testing
106105
install_amaltheas: ## Installs both version of amalthea in the. NOTE: It uses the currently active k8s context.
107106
helm repo add renku https://swissdatasciencecenter.github.io/helm-charts
108107
helm repo update
109-
helm upgrade --install amalthea-js renku/amalthea --version $(AMALTHEA_JS_VERSION)
110108
helm upgrade --install amalthea-se renku/amalthea-sessions --version ${AMALTHEA_SESSIONS_VERSION}
111109

112110
# TODO: Add the version variables from the top of the file here when the charts are fully published
113111
.PHONY: amalthea_schema
114112
amalthea_schema: ## Updates generates pydantic classes from CRDs
115113
curl https://raw.githubusercontent.com/SwissDataScienceCenter/amalthea/${AMALTHEA_SESSIONS_VERSION}/config/crd/bases/amalthea.dev_amaltheasessions.yaml | yq '.spec.versions[0].schema.openAPIV3Schema' | poetry run datamodel-codegen --output components/renku_data_services/notebooks/cr_amalthea_session.py --base-class renku_data_services.notebooks.cr_base.BaseCRD ${CR_CODEGEN_PARAMS}
116-
curl https://raw.githubusercontent.com/SwissDataScienceCenter/amalthea/${AMALTHEA_JS_VERSION}/controller/crds/jupyter_server.yaml | yq '.spec.versions[0].schema.openAPIV3Schema' | poetry run datamodel-codegen --output components/renku_data_services/notebooks/cr_jupyter_server.py --base-class renku_data_services.notebooks.cr_base.BaseCRD ${CR_CODEGEN_PARAMS}
117114

118115
.PHONY: shipwright_schema
119116
shipwright_schema: ## Updates the Shipwright pydantic classes

components/renku_data_services/notebooks/core_sessions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from renku_data_services.notebooks.api.schemas.cloud_storage import RCloneStorage
4848
from renku_data_services.notebooks.config import GitProviderHelperProto, NotebooksConfig
4949
from renku_data_services.notebooks.crs import (
50+
AmaltheaMetadata,
5051
AmaltheaSessionSpec,
5152
AmaltheaSessionV1Alpha1,
5253
AmaltheaSessionV1Alpha1MetadataPatch,
@@ -82,6 +83,7 @@
8283
SizeStr,
8384
State,
8485
Storage,
86+
Template,
8587
TlsSecret,
8688
)
8789
from renku_data_services.notebooks.image_check import ImageCheckRepository
@@ -865,7 +867,8 @@ async def start_session(
865867
annotations: dict[str, str] = {
866868
"renku.io/project_id": str(launcher.project_id),
867869
"renku.io/launcher_id": str(launcher_id),
868-
"renku.io/resource_class_id": str(resource_class_id),
870+
"renku.io/resource_class_id": str(resource_class.id),
871+
"renku.io/resource_pool_id": str(resource_pool.id),
869872
}
870873

871874
# Authentication
@@ -943,6 +946,8 @@ async def start_session(
943946
launcher_env_variables = get_launcher_env_variables(launcher, launch_request)
944947
env.extend(launcher_env_variables)
945948

949+
labels = {"renku.io/safe-username": user.id}
950+
946951
session = AmaltheaSessionV1Alpha1(
947952
metadata=Metadata(name=server_name, annotations=annotations),
948953
spec=AmaltheaSessionSpec(
@@ -991,6 +996,7 @@ async def start_session(
991996
tolerations=tolerations_from_resource_class(resource_class, nb_config.sessions.tolerations_model),
992997
affinity=node_affinity_from_resource_class(resource_class, nb_config.sessions.affinity_model),
993998
serviceAccountName=service_account_name,
999+
template=Template(metadata=AmaltheaMetadata(annotations=annotations, labels=labels)),
9941000
),
9951001
)
9961002
secrets_to_create = session_extras.secrets or []

components/renku_data_services/notebooks/cr_amalthea_session.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: <stdin>
3-
# timestamp: 2026-01-19T14:15:52+00:00
3+
# timestamp: 2026-02-10T13:31:41+00:00
44

55
from __future__ import annotations
66

@@ -3712,6 +3712,21 @@ class Session(BaseCRD):
37123712
)
37133713

37143714

3715+
class Metadata(BaseCRD):
3716+
model_config = ConfigDict(
3717+
extra="allow",
3718+
)
3719+
annotations: Optional[Mapping[str, str]] = None
3720+
labels: Optional[Mapping[str, str]] = None
3721+
3722+
3723+
class Template(BaseCRD):
3724+
model_config = ConfigDict(
3725+
extra="allow",
3726+
)
3727+
metadata: Optional[Metadata] = None
3728+
3729+
37153730
class Toleration(BaseCRD):
37163731
model_config = ConfigDict(
37173732
extra="allow",
@@ -3808,6 +3823,10 @@ class Spec(BaseCRD):
38083823
...,
38093824
description="Specification for the main session container that the user will access and use",
38103825
)
3826+
template: Optional[Template] = Field(
3827+
default=None,
3828+
description="Template for the fields that should be added to all children (and their children if applicable).",
3829+
)
38113830
tolerations: Optional[Sequence[Toleration]] = Field(
38123831
default=None,
38133832
description="If specified, the pod's tolerations.\nPassed right through to the Statefulset used for the session.",

components/renku_data_services/notebooks/crs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
State,
4747
Status,
4848
Storage,
49+
Template,
4950
TlsSecret,
5051
Toleration,
5152
)
@@ -57,6 +58,7 @@
5758
from renku_data_services.notebooks.cr_amalthea_session import Limits6 as _Limits
5859
from renku_data_services.notebooks.cr_amalthea_session import Limits7 as LimitsStr
5960
from renku_data_services.notebooks.cr_amalthea_session import Location as SessionLocation
61+
from renku_data_services.notebooks.cr_amalthea_session import Metadata as AmaltheaMetadata
6062
from renku_data_services.notebooks.cr_amalthea_session import Model as _ASModel
6163
from renku_data_services.notebooks.cr_amalthea_session import (
6264
PreferredDuringSchedulingIgnoredDuringExecutionItem1 as PreferredPodAffinityItem,

0 commit comments

Comments
 (0)