I am trying to achieve a shared directory for all users first. I created a shared-file folder in my Jupyterhub, through the dashboard.
Added this to my jupyterhub_config.py
I was looking for a similar feature which would allow us to adjust volume mounts based on certain user attributes.
However it seems like that both DockerSpawner and KubeSpawner both only accept a static volume mount configuration.
We probably need to extend the spawners to allow Callable's for these settings like KubeSpawner already does it for the profile list. The user could then provide a function within the configuration which adjusts the volumes based on the group membership or other attributes.
Currently, KubeSpawner users could maybe use the pod_modify_hook to accomplish the same thing.
This folder is only available to Admin - because I have created it from my admin account.
I want to make it readable to some users and read/writable for other group of users.
What is the best way to configure this?
For those who are interested, here is a little example on how to use the c.KubeSpawner.pod_modify_hook based on this post to mount additional PVCs into the users home dir.
Here I just use a static user -> volume map in a Python dict. Which allows you to also set the readOnly volumeMount option
erigrid = {
'name': 'villas4erigrid',
'pvc': 'group-villas4erigrid',
'mountPath': '/home/jovyan/villas4erigrid',
'readOnly': False
}
user_volume_map = {
'lrsxpv3p': [ erigrid ],
'vzi3jsam': [ erigrid ]
}
from kubernetes import client
from kubespawner.utils import get_k8s_model
from kubernetes.client.models import ( V1Volume, V1VolumeMount )
def modify_pod_hook(spawner, pod):
try:
user = spawner.user.name
if user in user_volume_map:
for volume in user_volume_map[user]:
pod.spec.volumes.append(
get_k8s_model(V1Volume, {
'name' : volume['name'],
'persistentVolumeClaim': {
'claimName': volume['pvc']
}
})
)
# Note implicitly only 1 container...
pod.spec.containers[0].volume_mounts.append(
get_k8s_model(V1VolumeMount, {
'name' : volume['name'],
'mountPath' : volume['mountPath'],
'readOnly': volume['readOnly']
})
)
except Exception as e:
spawner.log.info("Exception in shared-mounts" + str(e))
pass
return pod
c.KubeSpawner.modify_pod_hook = modify_pod_hook
@stv0g Hi ~~ Thanks for your great method. I have tried out your method which works well to access the PVC at the home directly. The PVC can be seen at all users’ home directory that I defined. However, could I ask is that act like a sharedrive for all the user or it s a separate mount point (i.e. one user’s change under that directory wont be seen by other user). I would like to define it as a sharedrive that one user’s change can be seen by all users. Is that workable?