@@ -1237,7 +1237,7 @@ func BenchmarkAuthorization(b *testing.B) {
1237
1237
},
1238
1238
}
1239
1239
1240
- podToAdd , _ := generatePod ("testwrite" , "ns0" , "node0" , "default" , opts )
1240
+ podToAdd , _ := generatePod ("testwrite" , "ns0" , "node0" , "default" , opts , rand . Perm )
1241
1241
1242
1242
b .ResetTimer ()
1243
1243
for _ , testWriteContention := range []bool {false , true } {
@@ -1338,11 +1338,11 @@ func populate(graph *Graph, nodes []*corev1.Node, pods []*corev1.Pod, pvs []*cor
1338
1338
}
1339
1339
}
1340
1340
1341
- func randomSubset (a , b int ) []int {
1341
+ func randomSubset (a , b int , randPerm func ( int ) [] int ) []int {
1342
1342
if b < a {
1343
1343
b = a
1344
1344
}
1345
- return rand . Perm (b )[:a ]
1345
+ return randPerm (b )[:a ]
1346
1346
}
1347
1347
1348
1348
// generate creates sample pods and persistent volumes based on the provided options.
@@ -1356,7 +1356,7 @@ func generate(opts *sampleDataOpts) ([]*corev1.Node, []*corev1.Pod, []*corev1.Pe
1356
1356
attachments := make ([]* storagev1.VolumeAttachment , 0 , opts .nodes * opts .attachmentsPerNode )
1357
1357
slices := make ([]* resourceapi.ResourceSlice , 0 , opts .nodes * opts .nodeResourceSlicesPerNode )
1358
1358
1359
- rand .Seed ( 12345 )
1359
+ r := rand .New ( rand . NewSource ( 12345 ) )
1360
1360
1361
1361
for n := 0 ; n < opts .nodes ; n ++ {
1362
1362
nodeName := fmt .Sprintf ("node%d" , n )
@@ -1365,7 +1365,7 @@ func generate(opts *sampleDataOpts) ([]*corev1.Node, []*corev1.Pod, []*corev1.Pe
1365
1365
namespace := fmt .Sprintf ("ns%d" , p % opts .namespaces )
1366
1366
svcAccountName := fmt .Sprintf ("svcacct%d-%s" , p , nodeName )
1367
1367
1368
- pod , podPVs := generatePod (name , namespace , nodeName , svcAccountName , opts )
1368
+ pod , podPVs := generatePod (name , namespace , nodeName , svcAccountName , opts , r . Perm )
1369
1369
pods = append (pods , pod )
1370
1370
pvs = append (pvs , podPVs ... )
1371
1371
}
@@ -1395,7 +1395,7 @@ func generate(opts *sampleDataOpts) ([]*corev1.Node, []*corev1.Pod, []*corev1.Pe
1395
1395
return nodes , pods , pvs , attachments , slices
1396
1396
}
1397
1397
1398
- func generatePod (name , namespace , nodeName , svcAccountName string , opts * sampleDataOpts ) (* corev1.Pod , []* corev1.PersistentVolume ) {
1398
+ func generatePod (name , namespace , nodeName , svcAccountName string , opts * sampleDataOpts , randPerm func ( int ) [] int ) (* corev1.Pod , []* corev1.PersistentVolume ) {
1399
1399
pvs := make ([]* corev1.PersistentVolume , 0 , opts .uniquePVCsPerPod + opts .sharedPVCsPerPod )
1400
1400
1401
1401
pod := & corev1.Pod {}
@@ -1410,7 +1410,7 @@ func generatePod(name, namespace, nodeName, svcAccountName string, opts *sampleD
1410
1410
}})
1411
1411
}
1412
1412
// Choose shared secrets randomly from shared secrets in a namespace.
1413
- subset := randomSubset (opts .sharedSecretsPerPod , opts .sharedSecretsPerNamespace )
1413
+ subset := randomSubset (opts .sharedSecretsPerPod , opts .sharedSecretsPerNamespace , randPerm )
1414
1414
for _ , i := range subset {
1415
1415
pod .Spec .Volumes = append (pod .Spec .Volumes , corev1.Volume {VolumeSource : corev1.VolumeSource {
1416
1416
Secret : & corev1.SecretVolumeSource {SecretName : fmt .Sprintf ("secret%d-shared" , i )},
@@ -1423,7 +1423,7 @@ func generatePod(name, namespace, nodeName, svcAccountName string, opts *sampleD
1423
1423
}})
1424
1424
}
1425
1425
// Choose shared configmaps randomly from shared configmaps in a namespace.
1426
- subset = randomSubset (opts .sharedConfigMapsPerPod , opts .sharedConfigMapsPerNamespace )
1426
+ subset = randomSubset (opts .sharedConfigMapsPerPod , opts .sharedConfigMapsPerNamespace , randPerm )
1427
1427
for _ , i := range subset {
1428
1428
pod .Spec .Volumes = append (pod .Spec .Volumes , corev1.Volume {VolumeSource : corev1.VolumeSource {
1429
1429
ConfigMap : & corev1.ConfigMapVolumeSource {LocalObjectReference : corev1.LocalObjectReference {Name : fmt .Sprintf ("configmap%d-shared" , i )}},
@@ -1470,7 +1470,7 @@ func generatePod(name, namespace, nodeName, svcAccountName string, opts *sampleD
1470
1470
})
1471
1471
}
1472
1472
// Choose shared pvcs randomly from shared pvcs in a namespace.
1473
- subset = randomSubset (opts .sharedPVCsPerPod , opts .sharedPVCsPerNamespace )
1473
+ subset = randomSubset (opts .sharedPVCsPerPod , opts .sharedPVCsPerNamespace , randPerm )
1474
1474
for _ , i := range subset {
1475
1475
pv := & corev1.PersistentVolume {}
1476
1476
pv .Name = fmt .Sprintf ("pv%d-shared-%s" , i , pod .Namespace )
0 commit comments