@@ -2698,8 +2698,11 @@ def test_create_workload_with_pvc_volume_readonly(self, mock_k8s_client):
26982698 main_container = pod_spec ["containers" ][0 ]
26992699 mounts = main_container .get ("volumeMounts" , [])
27002700 models_mount = next ((m for m in mounts if m ["name" ] == "models-volume" ), None )
2701+ models_volume = next ((v for v in pod_spec ["volumes" ] if v ["name" ] == "models-volume" ), None )
27012702 assert models_mount is not None
27022703 assert models_mount ["readOnly" ] is True
2704+ assert models_volume is not None
2705+ assert models_volume ["persistentVolumeClaim" ]["readOnly" ] is True
27032706
27042707 def test_create_workload_with_pvc_volume_subpath (self , mock_k8s_client ):
27052708 """
@@ -2961,7 +2964,10 @@ def test_apply_volumes_to_pod_spec_same_pvc_multiple_mounts(self, mock_k8s_clien
29612964 # One volume definition for the shared PVC (first Volume name used)
29622965 assert len (pod_spec ["volumes" ]) == 1
29632966 assert pod_spec ["volumes" ][0 ]["name" ] == "skills"
2964- assert pod_spec ["volumes" ][0 ]["persistentVolumeClaim" ]["claimName" ] == "oss-pvc-r"
2967+ shared_volume = next ((v for v in pod_spec ["volumes" ] if v ["name" ] == "skills" ), None )
2968+ assert shared_volume is not None
2969+ assert shared_volume ["persistentVolumeClaim" ]["claimName" ] == "oss-pvc-r"
2970+ assert shared_volume ["persistentVolumeClaim" ]["readOnly" ] is True
29652971
29662972 # Two volumeMounts, both referencing the same volume name
29672973 mounts = pod_spec ["containers" ][0 ]["volumeMounts" ]
@@ -2971,3 +2977,67 @@ def test_apply_volumes_to_pod_spec_same_pvc_multiple_mounts(self, mock_k8s_clien
29712977 assert by_path ["/path/to/skills" ].get ("subPath" ) == "skill-hub/publish"
29722978 assert by_path ["/path/to/draft" ]["name" ] == "skills"
29732979 assert by_path ["/path/to/draft" ].get ("subPath" ) == "skill-hub/draft"
2980+
2981+ def test_apply_volumes_to_pod_spec_same_pvc_multiple_mounts_readwrite (self , mock_k8s_client ):
2982+ """Shared PVC mounts with read_only=False should keep source-level readOnly false."""
2983+ from opensandbox_server .api .schema import Volume , PVC
2984+
2985+ pod_spec = {
2986+ "containers" : [{"name" : "main" , "volumeMounts" : []}],
2987+ "volumes" : [],
2988+ }
2989+ volumes = [
2990+ Volume (
2991+ name = "skills" ,
2992+ pvc = PVC (claim_name = "oss-pvc-rw" ),
2993+ mount_path = "/path/to/skills" ,
2994+ sub_path = "skill-hub/publish" ,
2995+ read_only = False ,
2996+ ),
2997+ Volume (
2998+ name = "draft" ,
2999+ pvc = PVC (claim_name = "oss-pvc-rw" ),
3000+ mount_path = "/path/to/draft" ,
3001+ sub_path = "skill-hub/draft" ,
3002+ read_only = False ,
3003+ ),
3004+ ]
3005+
3006+ apply_volumes_to_pod_spec (pod_spec , volumes )
3007+
3008+ assert len (pod_spec ["volumes" ]) == 1
3009+ shared_volume = next ((v for v in pod_spec ["volumes" ] if v ["name" ] == "skills" ), None )
3010+ assert shared_volume is not None
3011+ assert shared_volume ["persistentVolumeClaim" ]["claimName" ] == "oss-pvc-rw"
3012+ assert shared_volume ["persistentVolumeClaim" ]["readOnly" ] is False
3013+
3014+ mounts = pod_spec ["containers" ][0 ]["volumeMounts" ]
3015+ assert len (mounts ) == 2
3016+ assert all (mount ["name" ] == "skills" for mount in mounts )
3017+ assert all (mount ["readOnly" ] is False for mount in mounts )
3018+
3019+ def test_apply_volumes_to_pod_spec_same_pvc_mixed_read_only_raises (self , mock_k8s_client ):
3020+ """Shared PVC mounts with mixed read_only values should fail fast."""
3021+ from opensandbox_server .api .schema import Volume , PVC
3022+
3023+ pod_spec = {
3024+ "containers" : [{"name" : "main" , "volumeMounts" : []}],
3025+ "volumes" : [],
3026+ }
3027+ volumes = [
3028+ Volume (
3029+ name = "skills" ,
3030+ pvc = PVC (claim_name = "oss-pvc-mixed" ),
3031+ mount_path = "/path/to/skills" ,
3032+ read_only = False ,
3033+ ),
3034+ Volume (
3035+ name = "draft" ,
3036+ pvc = PVC (claim_name = "oss-pvc-mixed" ),
3037+ mount_path = "/path/to/draft" ,
3038+ read_only = True ,
3039+ ),
3040+ ]
3041+
3042+ with pytest .raises (ValueError , match = "mixed read_only values" ):
3043+ apply_volumes_to_pod_spec (pod_spec , volumes )
0 commit comments