From 908aca26c4a523bff285ef414bd9a8cb9eba064b Mon Sep 17 00:00:00 2001 From: Alputer Date: Fri, 1 Nov 2024 14:21:36 +0100 Subject: [PATCH] feat(sessions): add recommended images to info endpoint (#688) --- docs/openapi.json | 36 ++++++++++++++++++++++++++++++++ reana_server/config.py | 15 +++++++++++++ reana_server/rest/info.py | 44 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/docs/openapi.json b/docs/openapi.json index fd83bc8f..e62b1e15 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -465,6 +465,17 @@ "title": "Default workspace", "value": "/usr/share" }, + "interactive_session_recommended_jupyter_images": { + "title": "Recommended Jupyter images for interactive sessions", + "value": [ + "docker.io/jupyter/scipy-notebook:notebook-6.4.5", + "docker.io/jupyter/scipy-notebook:notebook-9.4.5" + ] + }, + "interactive_sessions_custom_image_allowed": { + "title": "Whether users are allowed to spawn custom interactive session images", + "value": "False" + }, "kubernetes_max_memory_limit": { "title": "Maximum allowed memory limit for Kubernetes jobs", "value": "10Gi" @@ -617,6 +628,31 @@ }, "type": "object" }, + "interactive_session_recommended_jupyter_images": { + "properties": { + "title": { + "type": "string" + }, + "value": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "interactive_sessions_custom_image_allowed": { + "properties": { + "title": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "type": "object" + }, "kubernetes_max_memory_limit": { "properties": { "title": { diff --git a/reana_server/config.py b/reana_server/config.py index 7a74b9a0..6f774f34 100644 --- a/reana_server/config.py +++ b/reana_server/config.py @@ -428,6 +428,21 @@ def _get_rate_limit(env_variable: str, default: str) -> str: ) """Maximum allowed period (in days) for interactive session inactivity before automatic closure.""" +REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS = json.loads( + os.getenv("REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS", "{}") +) +"""Allowed and recommended environments to be used for interactive sessions.""" + +REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS_CUSTOM_ALLOWED = ( + str( + REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS.get("jupyter", {}).get( + "allow_custom", "false" + ) + ).lower() + == "true" +) +"""Whether users can set custom interactive session images or not.""" + # Kubernetes jobs timeout # ================== REANA_KUBERNETES_JOBS_TIMEOUT_LIMIT = os.getenv("REANA_KUBERNETES_JOBS_TIMEOUT_LIMIT") diff --git a/reana_server/rest/info.py b/reana_server/rest/info.py index b7ff1fab..a2b31e8b 100644 --- a/reana_server/rest/info.py +++ b/reana_server/rest/info.py @@ -24,6 +24,8 @@ REANA_KUBERNETES_JOBS_TIMEOUT_LIMIT, REANA_KUBERNETES_JOBS_MAX_USER_TIMEOUT_LIMIT, REANA_INTERACTIVE_SESSION_MAX_INACTIVITY_PERIOD, + REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS, + REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS_CUSTOM_ALLOWED, DASK_ENABLED, DASK_AUTOSCALER_ENABLED, REANA_DASK_CLUSTER_DEFAULT_NUMBER_OF_WORKERS, @@ -108,6 +110,22 @@ def info(user, **kwargs): # noqa type: string x-nullable: true type: object + interactive_session_recommended_jupyter_images: + properties: + title: + type: string + value: + type: array + items: + type: string + type: object + interactive_sessions_custom_image_allowed: + properties: + title: + type: string + value: + type: string + type: object maximum_kubernetes_jobs_timeout: properties: title: @@ -221,6 +239,17 @@ def info(user, **kwargs): # noqa "title": "Maximum timeout for Kubernetes jobs", "value": "1209600" }, + "interactive_session_recommended_jupyter_images": { + "title": "Recommended Jupyter images for interactive sessions", + "value": [ + 'docker.io/jupyter/scipy-notebook:notebook-6.4.5', + 'docker.io/jupyter/scipy-notebook:notebook-9.4.5', + ] + }, + "interactive_sessions_custom_image_allowed": { + "title": "Whether users are allowed to spawn custom interactive session images", + "value": "False" + }, "dask_enabled": { "title": "Dask workflows allowed in the cluster", "value": "False" @@ -301,6 +330,19 @@ def info(user, **kwargs): # noqa title="Maximum inactivity period in days before automatic closure of interactive sessions", value=REANA_INTERACTIVE_SESSION_MAX_INACTIVITY_PERIOD, ), + interactive_sessions_custom_image_allowed=dict( + title="Users can set custom interactive session images", + value=REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS_CUSTOM_ALLOWED, + ), + interactive_session_recommended_jupyter_images=dict( + title="Recommended Jupyter images for interactive sessions", + value=[ + item["image"] + for item in REANA_INTERACTIVE_SESSIONS_ENVIRONMENTS["jupyter"][ + "recommended" + ] + ], + ), dask_enabled=dict( title="Dask workflows allowed in the cluster", value=bool(DASK_ENABLED), @@ -375,6 +417,8 @@ class InfoSchema(Schema): StringNullableInfoValue ) kubernetes_max_memory_limit = fields.Nested(StringInfoValue) + interactive_session_recommended_jupyter_images = fields.Nested(ListStringInfoValue) + interactive_sessions_custom_image_allowed = fields.Nested(StringInfoValue) dask_enabled = fields.Nested(StringInfoValue) if DASK_ENABLED: dask_autoscaler_enabled = fields.Nested(StringInfoValue)