From e709f09e4b5456ad284c82aaa1fdb8244a031419 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 4 Feb 2025 22:43:58 -0600 Subject: [PATCH 1/7] support updated kubespawner --- .../files/jupyterhub/03-profiles.py | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py index b298ae5ae1..4e6bacaa2b 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py @@ -5,7 +5,6 @@ from pathlib import Path import z2jh -from tornado import gen def base_profile_home_mounts(username): @@ -512,7 +511,6 @@ def render_profile( return None profile = copy.copy(profile) - profile_kubespawner_override = profile.get("kubespawner_override") profile["kubespawner_override"] = functools.reduce( deep_merge, [ @@ -522,38 +520,27 @@ def render_profile( base_profile_extra_mounts(), configure_user(username, groups), configure_user_provisioned_repositories(username), - profile_kubespawner_override, + profile.get("kubespawner_override"), ], {}, ) - # We need to merge any env vars from the spawner with any overrides from the profile - # This is mainly to ensure JUPYTERHUB_ANYONE/GROUP is passed through from the spawner - # to control dashboard access. - envvars_fixed = {**(profile["kubespawner_override"].get("environment", {}))} - - def preserve_envvars(spawner): - # This adds in JUPYTERHUB_ANYONE/GROUP rather than overwrite all env vars, - # if set in the spawner for a dashboard to control access. - return { - **envvars_fixed, - **spawner.environment, + profile["kubespawner_override"]["environment"].update( + { **profile_argo_token(groups), **profile_conda_store_viewer_token(), } - - profile["kubespawner_override"]["environment"] = preserve_envvars + ) return profile -@gen.coroutine -def render_profiles(spawner): +async def render_profiles(spawner): # jupyterhub does not yet manage groups but it will soon # so for now we rely on auth_state from the keycloak # userinfo request to have the groups in the key # "auth_state.oauth_user.groups" - auth_state = yield spawner.user.get_auth_state() + auth_state = await spawner.user.get_auth_state() username = auth_state["oauth_user"]["preferred_username"] @@ -570,7 +557,7 @@ def render_profiles(spawner): # fetch available profiles and render additional attributes profile_list = z2jh.get_config("custom.profiles") - return list( + rendered_profiles = list( filter( None, [ @@ -585,6 +572,7 @@ def render_profiles(spawner): ], ) ) + return rendered_profiles c.KubeSpawner.args = ["--debug"] From 582903800ca54ecf66ea646bed08d4acf765b405 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:13:21 -0600 Subject: [PATCH 2/7] add new default_image so we can test the PR --- .github/actions/init-local/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/actions/init-local/action.yml b/.github/actions/init-local/action.yml index 306876973a..a3d0438558 100644 --- a/.github/actions/init-local/action.yml +++ b/.github/actions/init-local/action.yml @@ -75,6 +75,12 @@ runs: size: 1Gi EOM + # Change jupyterhub image for PR testing purposes + cat >> '${{ steps.metadata.outputs.config }}' <<- EOM + default_images: + jupyterhub: quay.io/nebari/nebari-jupyterhub:jhub-fancy-profiles + EOM + - shell: bash run: | # Display Nebari config From 93b71125cae391ef66daaee1a04fe011ca49fe43 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Mon, 3 Mar 2025 16:36:04 -0600 Subject: [PATCH 3/7] Revert "add new default_image so we can test the PR" This reverts commit 582903800ca54ecf66ea646bed08d4acf765b405. --- .github/actions/init-local/action.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/init-local/action.yml b/.github/actions/init-local/action.yml index a3d0438558..306876973a 100644 --- a/.github/actions/init-local/action.yml +++ b/.github/actions/init-local/action.yml @@ -75,12 +75,6 @@ runs: size: 1Gi EOM - # Change jupyterhub image for PR testing purposes - cat >> '${{ steps.metadata.outputs.config }}' <<- EOM - default_images: - jupyterhub: quay.io/nebari/nebari-jupyterhub:jhub-fancy-profiles - EOM - - shell: bash run: | # Display Nebari config From 1051be1dc833a351f4e250c3cd54c2489186e43b Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:15:23 -0600 Subject: [PATCH 4/7] Reapply "add new default_image so we can test the PR" This reverts commit 93b71125cae391ef66daaee1a04fe011ca49fe43. --- .github/actions/init-local/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/actions/init-local/action.yml b/.github/actions/init-local/action.yml index 306876973a..a3d0438558 100644 --- a/.github/actions/init-local/action.yml +++ b/.github/actions/init-local/action.yml @@ -75,6 +75,12 @@ runs: size: 1Gi EOM + # Change jupyterhub image for PR testing purposes + cat >> '${{ steps.metadata.outputs.config }}' <<- EOM + default_images: + jupyterhub: quay.io/nebari/nebari-jupyterhub:jhub-fancy-profiles + EOM + - shell: bash run: | # Display Nebari config From 4d2e89a6bceb2816d902be9598c52ef953b95120 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:48:18 -0600 Subject: [PATCH 5/7] fix profile options issue when not specified --- src/_nebari/stages/kubernetes_services/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/__init__.py b/src/_nebari/stages/kubernetes_services/__init__.py index 0cbde34d69..5dd6f846e9 100644 --- a/src/_nebari/stages/kubernetes_services/__init__.py +++ b/src/_nebari/stages/kubernetes_services/__init__.py @@ -159,7 +159,7 @@ class JupyterLabProfile(schema.Base): users: Optional[List[str]] = None groups: Optional[List[str]] = None kubespawner_override: Optional[KubeSpawner] = None - profile_options: Optional[dict[str, ProfileOption]] = None + profile_options: dict[str, ProfileOption] = {} @model_validator(mode="after") def only_yaml_can_have_groups_and_users(self): From b153dac54d43e44e986dcc0d5e3a823b8728d15d Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:51:48 -0600 Subject: [PATCH 6/7] Revert "Reapply "add new default_image so we can test the PR"" This reverts commit 1051be1dc833a351f4e250c3cd54c2489186e43b. --- .github/actions/init-local/action.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/init-local/action.yml b/.github/actions/init-local/action.yml index a3d0438558..306876973a 100644 --- a/.github/actions/init-local/action.yml +++ b/.github/actions/init-local/action.yml @@ -75,12 +75,6 @@ runs: size: 1Gi EOM - # Change jupyterhub image for PR testing purposes - cat >> '${{ steps.metadata.outputs.config }}' <<- EOM - default_images: - jupyterhub: quay.io/nebari/nebari-jupyterhub:jhub-fancy-profiles - EOM - - shell: bash run: | # Display Nebari config From ffc77d6341f6026bdaf2327e2b8a4fc7fe1b1308 Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 4 Mar 2025 11:14:10 -0600 Subject: [PATCH 7/7] fix SyntaxWarning where we failed to escape a backslash --- .../services/jupyterhub/files/jupyterhub/03-profiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py index 4e6bacaa2b..5b32cd3370 100644 --- a/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py +++ b/src/_nebari/stages/kubernetes_services/template/modules/kubernetes/services/jupyterhub/files/jupyterhub/03-profiles.py @@ -51,7 +51,7 @@ def base_profile_home_mounts(username): # Copy skel files/folders not starting with '..' to user home directory. # Filtering out ..* removes some unneeded folders (k8s configmap mount implementation details). "find /etc/skel/. -maxdepth 1 -not -name '.' -not -name '..*' -exec " - "cp -rL {escaped_brackets} /mnt/{path} \;" + "cp -rL {escaped_brackets} /mnt/{path} \\;" ) command = MKDIR_OWN_DIRECTORY.format( # have to escape the brackets since this string will be formatted later by KubeSpawner