jupyterhub / kubespawner

Kubernetes spawner for JupyterHub
https://jupyterhub-kubespawner.readthedocs.io
BSD 3-Clause "New" or "Revised" License
549 stars 305 forks source link

JUPYTERHUB env variables for init containers #855

Open lahwaacz opened 1 month ago

lahwaacz commented 1 month ago

Proposed change

I would like to do some user-specific configuration in init containers. For this I need the current username on JupyterHub, which is normally set in the JUPYTERHUB_USER environment variable. However, it seems that init containers of the singleuser pod don't get any of the JUPYTERHUB_* environment variables.

Alternative options

None?

Who would use this feature?

(Optional): Suggest a solution

jabbera commented 1 month ago

We pass this in using a custom hook. For us this wouldn't remove our requirement for the hook so it's not a big deal, but it might work for you.

lahwaacz commented 1 month ago

@jabbera Can you elaborate? Can you give an example of the custom hook, ideally?

jabbera commented 1 month ago

@lahwaacz During configuration you can set:


c.Spawner.pre_spawn_hook = Your_pre_spawn_hook

async def Your_pre_spawn_hook(self, spawner: KubeSpawner) -> None:
            spawner.init_containers[0]["env"] += [
                V1EnvVar(name="JUPYTERHUB_USER", value=spawner.user.name),
                V1EnvVar(name="JUPYTERHUB_SERVER_NAME", value=spawner.name),
            ]

I agree it's silly these are not set by default.