From 32f62f8dbcb498727e964e1da8260c46c7966a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Krassowski?= <5832902+krassowski@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:45:39 +0000 Subject: [PATCH] Expose jupyter's preferred dir as a config option (#2251) --- src/_nebari/stages/kubernetes_services/__init__.py | 5 +++++ .../stages/kubernetes_services/template/jupyterhub.tf | 7 +++++++ .../modules/kubernetes/services/jupyterhub/configmaps.tf | 1 + .../jupyterhub/files/jupyter/jupyter_server_config.py.tpl | 4 ++++ .../modules/kubernetes/services/jupyterhub/variables.tf | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/src/_nebari/stages/kubernetes_services/__init__.py b/src/_nebari/stages/kubernetes_services/__init__.py index 8542ceb9d..69ae5b4b1 100644 --- a/src/_nebari/stages/kubernetes_services/__init__.py +++ b/src/_nebari/stages/kubernetes_services/__init__.py @@ -229,6 +229,7 @@ class IdleCuller(schema.Base): class JupyterLab(schema.Base): idle_culler: IdleCuller = IdleCuller() initial_repositories: typing.List[typing.Dict[str, str]] = [] + preferred_dir: typing.Optional[str] = None class InputSchema(schema.Base): @@ -363,6 +364,9 @@ class JupyterhubInputVars(schema.Base): argo_workflows_enabled: bool = Field(alias="argo-workflows-enabled") jhub_apps_enabled: bool = Field(alias="jhub-apps-enabled") cloud_provider: str = Field(alias="cloud-provider") + jupyterlab_preferred_dir: typing.Optional[str] = Field( + alias="jupyterlab-preferred-dir" + ) class DaskGatewayInputVars(schema.Base): @@ -501,6 +505,7 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]): argo_workflows_enabled=self.config.argo_workflows.enabled, jhub_apps_enabled=self.config.jhub_apps.enabled, initial_repositories=str(self.config.jupyterlab.initial_repositories), + jupyterlab_preferred_dir=self.config.jupyterlab.preferred_dir, ) dask_gateway_vars = DaskGatewayInputVars( diff --git a/src/_nebari/stages/kubernetes_services/template/jupyterhub.tf b/src/_nebari/stages/kubernetes_services/template/jupyterhub.tf index 76bc13e47..d4f60352f 100644 --- a/src/_nebari/stages/kubernetes_services/template/jupyterhub.tf +++ b/src/_nebari/stages/kubernetes_services/template/jupyterhub.tf @@ -39,6 +39,11 @@ variable "jupyterlab-profiles" { description = "JupyterHub profiles to expose to user" } +variable "jupyterlab-preferred-dir" { + description = "Directory in which the JupyterLab should open the file browser" + type = string +} + variable "initial-repositories" { description = "Map of folder location and git repo url to clone" type = string @@ -144,4 +149,6 @@ module "jupyterhub" { jupyterlab-pioneer-enabled = var.jupyterlab-pioneer-enabled jupyterlab-pioneer-log-format = var.jupyterlab-pioneer-log-format + + jupyterlab-preferred-dir = var.jupyterlab-preferred-dir } diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf index 4b6561129..daae8da2f 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/configmaps.tf @@ -7,6 +7,7 @@ locals { kernel_cull_connected = var.idle-culler-settings.kernel_cull_connected ? "True" : "False" # for Python compatible boolean values kernel_cull_busy = var.idle-culler-settings.kernel_cull_busy ? "True" : "False" # for Python compatible boolean values server_shutdown_no_activity_timeout = var.idle-culler-settings.server_shutdown_no_activity_timeout + jupyterlab_preferred_dir = var.jupyterlab-preferred-dir != null ? var.jupyterlab-preferred-dir : "" } ) } diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl index 79e3ec37d..ab5117ee1 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyter/jupyter_server_config.py.tpl @@ -9,6 +9,10 @@ c.ContentsManager.allow_hidden = True c.FileContentsManager.allow_hidden = True +# Set the preferred path for the frontend to start in +preferred_dir = ${jupyterlab_preferred_dir} +c.FileContentsManager.preferred_dir = preferred_dir if preferred_dir else None + # Timeout (in seconds) in which a terminal has been inactive and ready to # be culled. c.TerminalManager.cull_inactive_timeout = ${terminal_cull_inactive_timeout} * 60 diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/variables.tf b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/variables.tf index 4b3ed0f0a..24d154318 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/variables.tf +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/variables.tf @@ -168,6 +168,11 @@ variable "jupyterlab-pioneer-log-format" { type = string } +variable "jupyterlab-preferred-dir" { + description = "Directory in which the JupyterLab should open the file browser" + type = string +} + variable "cloud-provider" { description = "Name of cloud provider." type = string