Skip to content

Commit cf3ab22

Browse files
author
Jaehyeon1020
committed
fix: prevent duplicate volumes when same PVC is mounted to multiple paths
When the same PVC is configured with multiple mount paths in the web UI, the volume creation loop calls add_notebook_volume for each mount, adding a V1Volume with the same name multiple times. This causes a Kubernetes validation error due to duplicate volume names in the PodSpec. Track already-added volume names in the loop to skip duplicates while still adding all volume mounts. Signed-off-by: Jaehyeon1020 <[email protected]>
1 parent e001685 commit cf3ab22

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

components/crud-web-apps/jupyter/backend/apps/common/volumes_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,31 @@ def test_use_pvc_name_in_volume_source(self):
111111
"claimName": PVC_NAME,
112112
},
113113
})
114+
115+
116+
class TestAddNotebookVolume(unittest.TestCase):
117+
"""Test the functionality of the add_notebook_volume function."""
118+
119+
def setUp(self):
120+
"""Create a minimal Notebook CR dict."""
121+
self.notebook = {
122+
"spec": {
123+
"template": {
124+
"spec": {
125+
"containers": [{"volumeMounts": []}],
126+
},
127+
},
128+
},
129+
}
130+
self.volume = {
131+
"name": PVC_NAME,
132+
"persistentVolumeClaim": {"claimName": PVC_NAME},
133+
}
134+
135+
def test_add_volume(self):
136+
"""Add a volume to the Notebook's PodSpec."""
137+
volumes.add_notebook_volume(self.notebook, self.volume)
138+
podspec = self.notebook["spec"]["template"]["spec"]
139+
self.assertEqual(len(podspec["volumes"]), 1)
140+
self.assertEqual(podspec["volumes"][0]["name"], PVC_NAME)
141+

components/crud-web-apps/jupyter/backend/apps/default/routes/post.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def post_pvc(namespace):
5757
api.create_pvc(pvc, namespace, dry_run=True)
5858

5959
# create the new PVCs and set the Notebook volumes and mounts
60+
added_volumes = set()
6061
for api_volume in api_volumes:
6162
pvc = volumes.get_new_pvc(api_volume)
6263
if pvc is not None:
@@ -66,7 +67,10 @@ def post_pvc(namespace):
6667
v1_volume = volumes.get_pod_volume(api_volume, pvc)
6768
mount = volumes.get_container_mount(api_volume, v1_volume["name"])
6869

69-
notebook = volumes.add_notebook_volume(notebook, v1_volume)
70+
if v1_volume["name"] not in added_volumes:
71+
notebook = volumes.add_notebook_volume(notebook, v1_volume)
72+
added_volumes.add(v1_volume["name"])
73+
7074
notebook = volumes.add_notebook_container_mount(notebook, mount)
7175

7276
log.info("Creating Notebook: %s", notebook)

0 commit comments

Comments
 (0)