-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared-private-volumes.py
More file actions
45 lines (40 loc) · 1.43 KB
/
shared-private-volumes.py
File metadata and controls
45 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from kubespawner.utils import get_k8s_model
from kubernetes_asyncio.client.models import ( V1Volume, V1VolumeMount )
naep_competition = {
'name': 'naep-competition',
'pvc': 'naep-competition-storage-claim',
'mountPath': '/home/jovyan/naep-competition',
'readOnly': False
}
user_volume_map = {
'langdon-holmes': [naep_competition],
'scott-crossley': [naep_competition],
'wesley-morris': [naep_competition],
'learlab': [naep_competition],
}
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