I am trying to change my notebook root directory from /home/jovyan to /home/jovyan/{username}.
Initially i tried to use this inside extraConfig inside hub spawner.notebook_dir = f"/home/jovyan/{username}" but it didn’t work as the username was rendered as shaik\, sameer for spawner.user.name and shaik-5C-2C-20sameer in case of username inside singleuser.
so i tried this approach as the username was finally being rendered as shaiksameer but the pvc was being created as claim-shaik-5c-2c-20sameer
here is the code:
extraConfig:
set_safe_username: |
def safe_username(username):
return username.replace(",", "").replace(" ", "").replace("\\", "").lower()
def notebook_dir_hook(spawner):
import logging
raw_username = spawner.user.name
safe_name = safe_username(raw_username)
spawner.user.name = safe_name # Needed for PVC, pod, etc.
spawner.environment.update({
"NB_USER": safe_name,
"NB_UID": "1000"
})
spawner.notebook_dir = f"/home/jovyan/{safe_name}"
c.KubeSpawner.pre_spawn_hook = notebook_dir_hook
singleuser:
storage:
type: dynamic
extraLabels: {}
extraVolumes: []
extraVolumeMounts: []
static:
pvcName:
subPath: "{username}"
capacity: 1Gi # have change to 10Gi later
homeMountPath: /home/jovyan/{username}
dynamic:
storageClass:
pvcNameTemplate: claim-{username}{servername}
volumeNameTemplate: volume-{username}{servername}
storageAccessModes: [ReadWriteOnce]
why the pvc name template is not being created with safe_name