@@ -28,6 +28,7 @@ import (
28
28
29
29
api "k8s.io/api/core/v1"
30
30
storage "k8s.io/api/storage/v1"
31
+ storagev1beta1 "k8s.io/api/storage/v1beta1"
31
32
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
32
33
"k8s.io/apimachinery/pkg/types"
33
34
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -151,13 +152,16 @@ func MounterSetUpTests(t *testing.T, podInfoEnabled bool) {
151
152
for _ , test := range tests {
152
153
t .Run (test .name , func (t * testing.T ) {
153
154
klog .Infof ("Starting test %s" , test .name )
155
+ // Modes must be set if (and only if) CSIInlineVolume is enabled.
156
+ var modes []storagev1beta1.VolumeLifecycleMode
154
157
if test .csiInlineVolume {
155
158
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIInlineVolume , true )()
159
+ modes = append (modes , storagev1beta1 .VolumeLifecyclePersistent )
156
160
}
157
161
fakeClient := fakeclient .NewSimpleClientset (
158
- getTestCSIDriver ("no-info" , & noPodMountInfo , nil ),
159
- getTestCSIDriver ("info" , & currentPodInfoMount , nil ),
160
- getTestCSIDriver ("nil" , nil , nil ),
162
+ getTestCSIDriver ("no-info" , & noPodMountInfo , nil , modes ),
163
+ getTestCSIDriver ("info" , & currentPodInfoMount , nil , modes ),
164
+ getTestCSIDriver ("nil" , nil , nil , modes ),
161
165
)
162
166
plug , tmpDir := newTestPlugin (t , fakeClient )
163
167
defer os .RemoveAll (tmpDir )
@@ -278,16 +282,16 @@ func TestMounterSetUpSimple(t *testing.T) {
278
282
testCases := []struct {
279
283
name string
280
284
podUID types.UID
281
- mode csiVolumeMode
285
+ mode storagev1beta1. VolumeLifecycleMode
282
286
fsType string
283
287
options []string
284
288
spec func (string , []string ) * volume.Spec
285
289
shouldFail bool
286
290
}{
287
291
{
288
- name : "setup with vol source" ,
292
+ name : "setup with ephemeral source" ,
289
293
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
290
- mode : ephemeralVolumeMode ,
294
+ mode : storagev1beta1 . VolumeLifecycleEphemeral ,
291
295
fsType : "ext4" ,
292
296
shouldFail : true ,
293
297
spec : func (fsType string , options []string ) * volume.Spec {
@@ -299,7 +303,7 @@ func TestMounterSetUpSimple(t *testing.T) {
299
303
{
300
304
name : "setup with persistent source" ,
301
305
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
302
- mode : persistentVolumeMode ,
306
+ mode : storagev1beta1 . VolumeLifecyclePersistent ,
303
307
fsType : "zfs" ,
304
308
spec : func (fsType string , options []string ) * volume.Spec {
305
309
pvSrc := makeTestPV ("pv1" , 20 , testDriver , "vol1" )
@@ -311,7 +315,7 @@ func TestMounterSetUpSimple(t *testing.T) {
311
315
{
312
316
name : "setup with persistent source without unspecified fstype and options" ,
313
317
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
314
- mode : persistentVolumeMode ,
318
+ mode : storagev1beta1 . VolumeLifecyclePersistent ,
315
319
spec : func (fsType string , options []string ) * volume.Spec {
316
320
return volume .NewSpecFromPersistentVolume (makeTestPV ("pv1" , 20 , testDriver , "vol2" ), false )
317
321
},
@@ -345,8 +349,8 @@ func TestMounterSetUpSimple(t *testing.T) {
345
349
csiMounter := mounter .(* csiMountMgr )
346
350
csiMounter .csiClient = setupClient (t , true )
347
351
348
- if csiMounter .csiVolumeMode != persistentVolumeMode {
349
- t .Fatal ("unexpected volume mode: " , csiMounter .csiVolumeMode )
352
+ if csiMounter .volumeLifecycleMode != storagev1beta1 . VolumeLifecyclePersistent {
353
+ t .Fatal ("unexpected volume mode: " , csiMounter .volumeLifecycleMode )
350
354
}
351
355
352
356
attachID := getAttachmentName (csiMounter .volumeID , string (csiMounter .driverName ), string (plug .host .GetNodeName ()))
@@ -397,14 +401,10 @@ func TestMounterSetUpSimple(t *testing.T) {
397
401
func TestMounterSetUpWithInline (t * testing.T ) {
398
402
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .CSIInlineVolume , true )()
399
403
400
- fakeClient := fakeclient .NewSimpleClientset ()
401
- plug , tmpDir := newTestPlugin (t , fakeClient )
402
- defer os .RemoveAll (tmpDir )
403
-
404
404
testCases := []struct {
405
405
name string
406
406
podUID types.UID
407
- mode csiVolumeMode
407
+ mode storagev1beta1. VolumeLifecycleMode
408
408
fsType string
409
409
options []string
410
410
spec func (string , []string ) * volume.Spec
@@ -413,7 +413,7 @@ func TestMounterSetUpWithInline(t *testing.T) {
413
413
{
414
414
name : "setup with vol source" ,
415
415
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
416
- mode : ephemeralVolumeMode ,
416
+ mode : storagev1beta1 . VolumeLifecycleEphemeral ,
417
417
fsType : "ext4" ,
418
418
spec : func (fsType string , options []string ) * volume.Spec {
419
419
volSrc := makeTestVol ("pv1" , testDriver )
@@ -424,7 +424,7 @@ func TestMounterSetUpWithInline(t *testing.T) {
424
424
{
425
425
name : "setup with persistent source" ,
426
426
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
427
- mode : persistentVolumeMode ,
427
+ mode : storagev1beta1 . VolumeLifecyclePersistent ,
428
428
fsType : "zfs" ,
429
429
spec : func (fsType string , options []string ) * volume.Spec {
430
430
pvSrc := makeTestPV ("pv1" , 20 , testDriver , "vol1" )
@@ -436,7 +436,7 @@ func TestMounterSetUpWithInline(t *testing.T) {
436
436
{
437
437
name : "setup with persistent source without unspecified fstype and options" ,
438
438
podUID : types .UID (fmt .Sprintf ("%08X" , rand .Uint64 ())),
439
- mode : persistentVolumeMode ,
439
+ mode : storagev1beta1 . VolumeLifecyclePersistent ,
440
440
spec : func (fsType string , options []string ) * volume.Spec {
441
441
return volume .NewSpecFromPersistentVolume (makeTestPV ("pv1" , 20 , testDriver , "vol2" ), false )
442
442
},
@@ -449,6 +449,15 @@ func TestMounterSetUpWithInline(t *testing.T) {
449
449
}
450
450
451
451
for _ , tc := range testCases {
452
+ // The fake driver currently supports all modes.
453
+ volumeLifecycleModes := []storagev1beta1.VolumeLifecycleMode {
454
+ storagev1beta1 .VolumeLifecycleEphemeral ,
455
+ storagev1beta1 .VolumeLifecyclePersistent ,
456
+ }
457
+ driver := getTestCSIDriver (testDriver , nil , nil , volumeLifecycleModes )
458
+ fakeClient := fakeclient .NewSimpleClientset (driver )
459
+ plug , tmpDir := newTestPlugin (t , fakeClient )
460
+ defer os .RemoveAll (tmpDir )
452
461
registerFakePlugin (testDriver , "endpoint" , []string {"1.0.0" }, t )
453
462
t .Run (tc .name , func (t * testing.T ) {
454
463
mounter , err := plug .NewMounter (
@@ -470,15 +479,15 @@ func TestMounterSetUpWithInline(t *testing.T) {
470
479
csiMounter := mounter .(* csiMountMgr )
471
480
csiMounter .csiClient = setupClient (t , true )
472
481
473
- if csiMounter .csiVolumeMode != tc .mode {
474
- t .Fatal ("unexpected volume mode: " , csiMounter .csiVolumeMode )
482
+ if csiMounter .volumeLifecycleMode != tc .mode {
483
+ t .Fatal ("unexpected volume mode: " , csiMounter .volumeLifecycleMode )
475
484
}
476
485
477
- if csiMounter .csiVolumeMode == ephemeralVolumeMode && csiMounter .volumeID != makeVolumeHandle (string (tc .podUID ), csiMounter .specVolumeID ) {
486
+ if csiMounter .volumeLifecycleMode == storagev1beta1 . VolumeLifecycleEphemeral && csiMounter .volumeID != makeVolumeHandle (string (tc .podUID ), csiMounter .specVolumeID ) {
478
487
t .Fatal ("unexpected generated volumeHandle:" , csiMounter .volumeID )
479
488
}
480
489
481
- if csiMounter .csiVolumeMode == persistentVolumeMode {
490
+ if csiMounter .volumeLifecycleMode == storagev1beta1 . VolumeLifecyclePersistent {
482
491
attachID := getAttachmentName (csiMounter .volumeID , string (csiMounter .driverName ), string (plug .host .GetNodeName ()))
483
492
attachment := makeTestAttachment (attachID , "test-node" , csiMounter .spec .Name ())
484
493
_ , err = csiMounter .k8s .StorageV1 ().VolumeAttachments ().Create (attachment )
@@ -503,10 +512,10 @@ func TestMounterSetUpWithInline(t *testing.T) {
503
512
}
504
513
505
514
// validate stagingTargetPath
506
- if tc .mode == ephemeralVolumeMode && vol .DeviceMountPath != "" {
515
+ if tc .mode == storagev1beta1 . VolumeLifecycleEphemeral && vol .DeviceMountPath != "" {
507
516
t .Errorf ("unexpected devicePathTarget sent to driver: %s" , vol .DeviceMountPath )
508
517
}
509
- if tc .mode == persistentVolumeMode {
518
+ if tc .mode == storagev1beta1 . VolumeLifecyclePersistent {
510
519
devicePath , err := makeDeviceMountPath (plug , csiMounter .spec )
511
520
if err != nil {
512
521
t .Fatal (err )
0 commit comments