@@ -360,9 +360,108 @@ var _ = ginkgo.Describe("[efs-csi] EFS CSI", func() {
360
360
encryptInTransit := false
361
361
testEncryptInTransit (f , & encryptInTransit )
362
362
})
363
+
364
+ ginkgo .It ("should successfully perform dynamic provisioning" , func () {
365
+
366
+ ginkgo .By ("Creating EFS Storage Class, PVC and associated PV" )
367
+ params := map [string ]string {
368
+ "provisioningMode" : "efs-ap" ,
369
+ "fileSystemId" : FileSystemId ,
370
+ "subPathPattern" : "${.PVC.name}" ,
371
+ "directoryPerms" : "700" ,
372
+ "gidRangeStart" : "1000" ,
373
+ "gidRangeEnd" : "2000" ,
374
+ "basePath" : "/dynamic_provisioning" ,
375
+ "ensureUniqueDirectory" : "true" ,
376
+ }
377
+
378
+ sc := GetStorageClass (params )
379
+ sc , err := f .ClientSet .StorageV1 ().StorageClasses ().Create (context .TODO (), sc , metav1.CreateOptions {})
380
+ framework .ExpectNoError (err , "creating storage class" )
381
+ pvc , err := createEFSPVCPVDynamicProvisioning (f .ClientSet , f .Namespace .Name , f .Namespace .Name , sc .Name )
382
+ framework .ExpectNoError (err , "creating pvc" )
383
+
384
+ ginkgo .By ("Deploying a pod that applies the PVC and writes data" )
385
+ testData := "DP TEST"
386
+ writePath := "/mnt/volume1/out"
387
+ writeCommand := fmt .Sprintf ("echo \" %s\" >> %s" , testData , writePath )
388
+ pod := e2epod .MakePod (f .Namespace .Name , nil , []* v1.PersistentVolumeClaim {pvc }, false , writeCommand )
389
+ pod , err = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (context .TODO (), pod , metav1.CreateOptions {})
390
+ framework .ExpectNoError (err , "creating pod" )
391
+ framework .ExpectNoError (e2epod .WaitForPodSuccessInNamespace (f .ClientSet , pod .Name , f .Namespace .Name ), "waiting for pod success" )
392
+ _ = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Delete (context .TODO (), pod .Name , metav1.DeleteOptions {})
393
+
394
+ ginkgo .By ("Deploying a second pod that reads the data" )
395
+ pod = e2epod .MakePod (f .Namespace .Name , nil , []* v1.PersistentVolumeClaim {pvc }, false , "while true; do echo $(date -u); sleep 5; done" )
396
+ pod , err = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (context .TODO (), pod , metav1.CreateOptions {})
397
+ framework .ExpectNoError (err , "creating pod" )
398
+ framework .ExpectNoError (e2epod .WaitForPodNameRunningInNamespace (f .ClientSet , pod .Name , f .Namespace .Name ), "waiting for pod running" )
399
+
400
+ readCommand := fmt .Sprintf ("cat %s" , writePath )
401
+ output := framework .RunKubectlOrDie (f .Namespace .Name , "exec" , pod .Name , "--" , "/bin/sh" , "-c" , readCommand )
402
+ output = strings .TrimSuffix (output , "\n " )
403
+ framework .Logf ("The output is: %s" , output )
404
+
405
+ defer func () {
406
+ _ = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Delete (context .TODO (), pod .Name , metav1.DeleteOptions {})
407
+ _ = f .ClientSet .CoreV1 ().PersistentVolumeClaims (f .Namespace .Name ).Delete (context .TODO (), pvc .Name , metav1.DeleteOptions {})
408
+ _ = f .ClientSet .StorageV1 ().StorageClasses ().Delete (context .TODO (), sc .Name , metav1.DeleteOptions {})
409
+ }()
410
+
411
+ if output == "" {
412
+ ginkgo .Fail ("Read data is empty." )
413
+ }
414
+ if output != testData {
415
+ ginkgo .Fail ("Read data does not match write data." )
416
+ }
417
+ })
418
+
363
419
})
364
420
})
365
421
422
+ func createEFSPVCPVDynamicProvisioning (c clientset.Interface , namespace , name , storageClassName string ) (* v1.PersistentVolumeClaim , error ) {
423
+ pvc := makeEFSPVCDynamicProvisioning (namespace , name , storageClassName )
424
+ pvc , err := c .CoreV1 ().PersistentVolumeClaims (namespace ).Create (context .TODO (), pvc , metav1.CreateOptions {})
425
+ if err != nil {
426
+ return nil , err
427
+ }
428
+ return pvc , nil
429
+ }
430
+
431
+ func makeEFSPVCDynamicProvisioning (namespace , name string , storageClassName string ) * v1.PersistentVolumeClaim {
432
+ return & v1.PersistentVolumeClaim {
433
+ ObjectMeta : metav1.ObjectMeta {
434
+ Name : name ,
435
+ Namespace : namespace ,
436
+ },
437
+ Spec : v1.PersistentVolumeClaimSpec {
438
+ AccessModes : []v1.PersistentVolumeAccessMode {v1 .ReadWriteMany },
439
+ Resources : v1.ResourceRequirements {
440
+ Requests : v1.ResourceList {
441
+ v1 .ResourceStorage : resource .MustParse ("1Gi" ),
442
+ },
443
+ },
444
+ StorageClassName : & storageClassName ,
445
+ },
446
+ }
447
+ }
448
+
449
+ func GetStorageClass (params map [string ]string ) * storagev1.StorageClass {
450
+ parameters := params
451
+
452
+ generateName := fmt .Sprintf ("efs-csi-dynamic-sc-test1234-" )
453
+
454
+ defaultBindingMode := storagev1 .VolumeBindingImmediate
455
+ return & storagev1.StorageClass {
456
+ ObjectMeta : metav1.ObjectMeta {
457
+ Name : generateName + generateRandomString (4 ),
458
+ },
459
+ Provisioner : "efs.csi.aws.com" ,
460
+ Parameters : parameters ,
461
+ VolumeBindingMode : & defaultBindingMode ,
462
+ }
463
+ }
464
+
366
465
func createEFSPVCPV (c clientset.Interface , namespace , name , path string , volumeAttributes map [string ]string ) (* v1.PersistentVolumeClaim , * v1.PersistentVolume , error ) {
367
466
pvc , pv := makeEFSPVCPV (namespace , name , path , volumeAttributes )
368
467
pvc , err := c .CoreV1 ().PersistentVolumeClaims (namespace ).Create (context .TODO (), pvc , metav1.CreateOptions {})
0 commit comments