@@ -408,6 +408,19 @@ func Test_nodePlugin_Admit(t *testing.T) {
408
408
},
409
409
}
410
410
411
+ azureFileCSIDriver = & storagev1.CSIDriver {
412
+ ObjectMeta : metav1.ObjectMeta {
413
+ Name : "file.csi.azure.com" ,
414
+ },
415
+ Spec : storagev1.CSIDriverSpec {
416
+ TokenRequests : []storagev1.TokenRequest {
417
+ {
418
+ Audience : "foo" ,
419
+ },
420
+ },
421
+ },
422
+ }
423
+
411
424
csiDriverIndex = cache .NewIndexer (cache .MetaNamespaceKeyFunc , nil )
412
425
csiDriverLister = storagelisters .NewCSIDriverLister (csiDriverIndex )
413
426
@@ -424,6 +437,16 @@ func Test_nodePlugin_Admit(t *testing.T) {
424
437
},
425
438
}
426
439
440
+ pvcWithIntreeAzureFile = & corev1.PersistentVolumeClaim {
441
+ ObjectMeta : metav1.ObjectMeta {
442
+ Name : "pvclaim-azurefile" ,
443
+ Namespace : "ns" ,
444
+ },
445
+ Spec : corev1.PersistentVolumeClaimSpec {
446
+ VolumeName : "pvname-azurefile" ,
447
+ },
448
+ }
449
+
427
450
ephemeralVolumePVCWithCSIDriver = & corev1.PersistentVolumeClaim {
428
451
ObjectMeta : metav1.ObjectMeta {
429
452
Name : "myephemeralpod-myvol" ,
@@ -451,6 +474,20 @@ func Test_nodePlugin_Admit(t *testing.T) {
451
474
},
452
475
}
453
476
477
+ pvWithIntreeAzureFile = & corev1.PersistentVolume {
478
+ ObjectMeta : metav1.ObjectMeta {
479
+ Name : "pvname-azurefile" ,
480
+ },
481
+ Spec : corev1.PersistentVolumeSpec {
482
+ ClaimRef : & corev1.ObjectReference {
483
+ Namespace : "ns" ,
484
+ },
485
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
486
+ AzureFile : & corev1.AzureFilePersistentVolumeSource {ShareName : "default" , SecretName : "secret" },
487
+ },
488
+ },
489
+ }
490
+
454
491
pvIndex = cache .NewIndexer (cache .MetaNamespaceKeyFunc , nil )
455
492
pvLister = corev1lister .NewPersistentVolumeLister (pvIndex )
456
493
@@ -463,6 +500,7 @@ func Test_nodePlugin_Admit(t *testing.T) {
463
500
projectedVolumeSource := & corev1.ProjectedVolumeSource {Sources : []corev1.VolumeProjection {{ServiceAccountToken : & corev1.ServiceAccountTokenProjection {Audience : "foo" }}}}
464
501
csiDriverVolumeSource := & corev1.CSIVolumeSource {Driver : "com.example.csi.mydriver" }
465
502
persistentVolumeClaimVolumeSource := & corev1.PersistentVolumeClaimVolumeSource {ClaimName : "pvclaim" }
503
+ persistentVolumeClaimVolumeSourceAzureFile := & corev1.PersistentVolumeClaimVolumeSource {ClaimName : "pvclaim-azurefile" }
466
504
ephemeralVolumeSource := & corev1.EphemeralVolumeSource {VolumeClaimTemplate : & corev1.PersistentVolumeClaimTemplate {}}
467
505
468
506
coremypodWithProjectedServiceAccountEmptyAudience , v1mypodWithProjectedServiceAccountEmptyAudience := makeTestPod ("ns" , "mysapod" , "mynode" , false )
@@ -483,10 +521,19 @@ func Test_nodePlugin_Admit(t *testing.T) {
483
521
coremypodWithPVCAndCSI , v1mypodWithPVCAndCSI := makeTestPod ("ns" , "mypvcandcsipod" , "mynode" , false )
484
522
v1mypodWithPVCAndCSI .Spec .Volumes = []corev1.Volume {{VolumeSource : corev1.VolumeSource {PersistentVolumeClaim : persistentVolumeClaimVolumeSource }}, {VolumeSource : corev1.VolumeSource {CSI : csiDriverVolumeSource }}}
485
523
524
+ coremypodIntreeInlineVolToCSI , v1mypodIntreeInlineVolToCSI := makeTestPod ("ns" , "myintreeinlinevoltocsipod" , "mynode" , false )
525
+ v1mypodIntreeInlineVolToCSI .Spec .Volumes = []corev1.Volume {{VolumeSource : corev1.VolumeSource {AzureFile : & corev1.AzureFileVolumeSource {ShareName : "default" , SecretName : "secret" }}}}
526
+
527
+ coremypodIntreePVToCSI , v1mypodIntreePVToCSI := makeTestPod ("ns" , "myintreepvtocsipod" , "mynode" , false )
528
+ v1mypodIntreePVToCSI .Spec .Volumes = []corev1.Volume {{VolumeSource : corev1.VolumeSource {PersistentVolumeClaim : persistentVolumeClaimVolumeSourceAzureFile }}}
529
+
486
530
checkNilError (t , csiDriverIndex .Add (csiDriverWithAudience ))
531
+ checkNilError (t , csiDriverIndex .Add (azureFileCSIDriver ))
487
532
checkNilError (t , pvcIndex .Add (pvcWithCSIDriver ))
533
+ checkNilError (t , pvcIndex .Add (pvcWithIntreeAzureFile ))
488
534
checkNilError (t , pvcIndex .Add (ephemeralVolumePVCWithCSIDriver ))
489
535
checkNilError (t , pvIndex .Add (pvWithCSIDriver ))
536
+ checkNilError (t , pvIndex .Add (pvWithIntreeAzureFile ))
490
537
491
538
existingPodsIndex .Add (v1mymirrorpod )
492
539
existingPodsIndex .Add (v1othermirrorpod )
@@ -501,6 +548,8 @@ func Test_nodePlugin_Admit(t *testing.T) {
501
548
checkNilError (t , existingPodsIndex .Add (v1mypodWithPVCRefCSI ))
502
549
checkNilError (t , existingPodsIndex .Add (v1mypodWithEphemeralVolume ))
503
550
checkNilError (t , existingPodsIndex .Add (v1mypodWithPVCAndCSI ))
551
+ checkNilError (t , existingPodsIndex .Add (v1mypodIntreePVToCSI ))
552
+ checkNilError (t , existingPodsIndex .Add (v1mypodIntreeInlineVolToCSI ))
504
553
505
554
existingNodesIndex .Add (& corev1.Node {ObjectMeta : mynodeObjMeta })
506
555
@@ -1430,6 +1479,30 @@ func Test_nodePlugin_Admit(t *testing.T) {
1430
1479
},
1431
1480
attributes : admission .NewAttributesRecord (makeTokenRequest (coremypodWithCSI .Name , v1mypodWithCSI .UID , []string {"foo" }), nil , tokenrequestKind , coremypod .Namespace , "mysa" , svcacctResource , "token" , admission .Create , & metav1.CreateOptions {}, false , mynode ),
1432
1481
},
1482
+ {
1483
+ name : "intree pv to csi, allow create of token when audience in pod --> csi --> driver --> tokenrequest with audience, ServiceAccountNodeAudienceRestriction=true" ,
1484
+ podsGetter : existingPods ,
1485
+ csiDriverGetter : csiDriverLister ,
1486
+ pvcGetter : pvcLister ,
1487
+ pvGetter : pvLister ,
1488
+ features : feature .DefaultFeatureGate ,
1489
+ setupFunc : func (t * testing.T ) {
1490
+ t .Helper ()
1491
+ featuregatetesting .SetFeatureGateDuringTest (t , feature .DefaultFeatureGate , features .ServiceAccountNodeAudienceRestriction , true )
1492
+ },
1493
+ attributes : admission .NewAttributesRecord (makeTokenRequest (coremypodIntreePVToCSI .Name , v1mypodIntreePVToCSI .UID , []string {"foo" }), nil , tokenrequestKind , coremypod .Namespace , "mysa" , svcacctResource , "token" , admission .Create , & metav1.CreateOptions {}, false , mynode ),
1494
+ },
1495
+ {
1496
+ name : "intree inline vol to csi, allow create of token when audience in pod --> csi --> driver --> tokenrequest with audience, ServiceAccountNodeAudienceRestriction=true" ,
1497
+ podsGetter : existingPods ,
1498
+ csiDriverGetter : csiDriverLister ,
1499
+ features : feature .DefaultFeatureGate ,
1500
+ setupFunc : func (t * testing.T ) {
1501
+ t .Helper ()
1502
+ featuregatetesting .SetFeatureGateDuringTest (t , feature .DefaultFeatureGate , features .ServiceAccountNodeAudienceRestriction , true )
1503
+ },
1504
+ attributes : admission .NewAttributesRecord (makeTokenRequest (coremypodIntreeInlineVolToCSI .Name , v1mypodIntreeInlineVolToCSI .UID , []string {"foo" }), nil , tokenrequestKind , coremypod .Namespace , "mysa" , svcacctResource , "token" , admission .Create , & metav1.CreateOptions {}, false , mynode ),
1505
+ },
1433
1506
1434
1507
// Unrelated objects
1435
1508
{
0 commit comments