Create directory in user home on startup

I got a user request to create a directory in the users home dirs.

We use NFS with a NFS provisioner for home directories. A static claim is deployed first, then:

singleuser:
  storage:
    type: static
    static:
      pvcName: jhub-let-01-17-claim

JupyterHub assigns notebook/user specific subdirectories as home directories.

I tried initContainer, but here the user is still unknown and the user directory not yet assigned, and the directory gets created in the root of the PV.

I managed to create the directory by adding a creator script to /etc/profiles.d in our custom notebook image, but this takes effect only after a terminal has been opened by the user.

I wonder if there is a better solution?

Assuming the initContainer is attached to the singleuser pod, the username must be known, otherwise JupyterHub (KubeSpawner) wouldn’t be able to launch the pod. How have you configured your initContainer?

Another option is to use a postStart hook:

Thanks, postStart is exactly what I searched but was too stupid to find. Runs in user context and independent of terminal launch, perfect.