File tree Expand file tree Collapse file tree 2 files changed +42
-4
lines changed
staging/src/k8s.io/csi-translation-lib/plugins Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,14 @@ func (g *gcePersistentDiskCSITranslator) TranslateInTreeInlineVolumeToCSI(volume
202
202
partition = strconv .Itoa (int (pdSource .Partition ))
203
203
}
204
204
205
- pv := & v1.PersistentVolume {
205
+ var am v1.PersistentVolumeAccessMode
206
+ if pdSource .ReadOnly {
207
+ am = v1 .ReadOnlyMany
208
+ } else {
209
+ am = v1 .ReadWriteOnce
210
+ }
211
+
212
+ return & v1.PersistentVolume {
206
213
ObjectMeta : metav1.ObjectMeta {
207
214
// A.K.A InnerVolumeSpecName required to match for Unmount
208
215
Name : volume .Name ,
@@ -219,10 +226,9 @@ func (g *gcePersistentDiskCSITranslator) TranslateInTreeInlineVolumeToCSI(volume
219
226
},
220
227
},
221
228
},
222
- AccessModes : []v1.PersistentVolumeAccessMode {v1 . ReadWriteOnce },
229
+ AccessModes : []v1.PersistentVolumeAccessMode {am },
223
230
},
224
- }
225
- return pv , nil
231
+ }, nil
226
232
}
227
233
228
234
// TranslateInTreePVToCSI takes a PV with GCEPersistentDisk set from in-tree
Original file line number Diff line number Diff line change @@ -369,3 +369,35 @@ func TestBackwardCompatibleAccessModes(t *testing.T) {
369
369
}
370
370
}
371
371
}
372
+
373
+ func TestInlineReadOnly (t * testing.T ) {
374
+ g := NewGCEPersistentDiskCSITranslator ()
375
+ pv , err := g .TranslateInTreeInlineVolumeToCSI (& v1.Volume {
376
+ VolumeSource : v1.VolumeSource {
377
+ GCEPersistentDisk : & v1.GCEPersistentDiskVolumeSource {
378
+ PDName : "foo" ,
379
+ ReadOnly : true ,
380
+ },
381
+ },
382
+ })
383
+ if err != nil {
384
+ t .Fatalf ("Failed to translate in tree inline volume to CSI: %v" , err )
385
+ }
386
+
387
+ if pv == nil || pv .Spec .PersistentVolumeSource .CSI == nil {
388
+ t .Fatal ("PV or volume source unexpectedly nil" )
389
+ }
390
+
391
+ if ! pv .Spec .PersistentVolumeSource .CSI .ReadOnly {
392
+ t .Error ("PV readonly value not true" )
393
+ }
394
+
395
+ ams := pv .Spec .AccessModes
396
+ if len (ams ) != 1 {
397
+ t .Errorf ("got am %v, expected length of 1" , ams )
398
+ }
399
+
400
+ if ams [0 ] != v1 .ReadOnlyMany {
401
+ t .Errorf ("got am %v, expected access mode of ReadOnlyMany" , ams [0 ])
402
+ }
403
+ }
You can’t perform that action at this time.
0 commit comments