@@ -200,6 +200,9 @@ func TestAllocator(t *testing.T) {
200
200
// },
201
201
// },
202
202
// }
203
+
204
+ // Slices
205
+
203
206
node1slice := unmarshal [resourceapi.ResourceSlice ](t , `
204
207
metadata:
205
208
name: worker-1-slice
@@ -218,6 +221,10 @@ spec:
218
221
version: 1.0.0
219
222
numa:
220
223
int: 1
224
+ stringAttribute:
225
+ string: stringAttributeValue
226
+ boolAttribute:
227
+ bool: true
221
228
capacity:
222
229
memory: 1Gi # small
223
230
- name: device-2
@@ -227,6 +234,10 @@ spec:
227
234
version: 1.0.0
228
235
numa:
229
236
int: 1
237
+ stringAttribute:
238
+ string: stringAttributeValue
239
+ boolAttribute:
240
+ bool: true
230
241
capacity:
231
242
memory: 2Gi # large
232
243
` )
@@ -247,18 +258,26 @@ spec:
247
258
basic:
248
259
attributes:
249
260
driverVersion:
250
- version: 1 .0.0
261
+ version: 2 .0.0
251
262
numa:
252
- int: 1
263
+ int: 2
264
+ stringAttribute:
265
+ string: stringAttributeValue2
266
+ boolAttribute:
267
+ bool: false
253
268
capacity:
254
269
memory: 1Gi # small
255
270
- name: device-6
256
271
basic:
257
272
attributes:
258
273
driverVersion:
259
- version: 1 .0.0
274
+ version: 2 .0.0
260
275
numa:
261
- int: 1
276
+ int: 2
277
+ stringAttribute:
278
+ string: stringAttributeValue2
279
+ boolAttribute:
280
+ bool: false
262
281
capacity:
263
282
memory: 2Gi # large
264
283
` )
@@ -424,7 +443,7 @@ spec:
424
443
basic:
425
444
attributes:
426
445
driverVersion:
427
- version: 1 .0.0
446
+ version: 2 .0.0
428
447
numa:
429
448
int: 1
430
449
capacity:
@@ -433,13 +452,15 @@ spec:
433
452
basic:
434
453
attributes:
435
454
driverVersion:
436
- version: 1 .0.0
455
+ version: 2 .0.0
437
456
numa:
438
457
int: 1
439
458
capacity:
440
459
memory: 2Gi # large
441
460
` )
442
461
462
+ // Claims
463
+
443
464
simpleClaim := unmarshal [resourceapi.ResourceClaim ](t , `
444
465
metadata:
445
466
name: claim
@@ -480,6 +501,30 @@ spec:
480
501
parameters: {"deviceAttribute":"deviceAttributeValue"}
481
502
` )
482
503
504
+ simpleClaimWithUnknownClassName := unmarshal [resourceapi.ResourceClaim ](t , `
505
+ metadata:
506
+ name: claim
507
+ spec:
508
+ devices:
509
+ requests:
510
+ - name: req-0
511
+ countMode: Exact
512
+ count: 1
513
+ deviceClassName: unknown-class
514
+ ` )
515
+
516
+ simpleClaimWithEmptyClassName := unmarshal [resourceapi.ResourceClaim ](t , `
517
+ metadata:
518
+ name: claim
519
+ spec:
520
+ devices:
521
+ requests:
522
+ - name: req-0
523
+ countMode: Exact
524
+ count: 1
525
+ deviceClassName: ""
526
+ ` )
527
+
483
528
allocatedSimpleClaim := unmarshal [resourceapi.AllocationResult ](t , `
484
529
devices:
485
530
results:
@@ -607,6 +652,83 @@ spec:
607
652
expression: device.capacity["driver-a"].memory.compareTo(quantity("2Gi")) >= 0
608
653
` )
609
654
655
+ twoDeviceClaimWithConstraint := unmarshal [resourceapi.ResourceClaim ](t , `
656
+ metadata:
657
+ name: claim
658
+ spec:
659
+ devices:
660
+ requests:
661
+ - name: req-0
662
+ countMode: Exact
663
+ count: 1
664
+ deviceClassName: driver-a
665
+ - name: req-1
666
+ countMode: Exact
667
+ count: 1
668
+ deviceClassName: driver-a
669
+ constraints:
670
+ - matchAttribute: numa
671
+ - matchAttribute: driverVersion
672
+ - matchAttribute: stringAttribute
673
+ - matchAttribute: boolAttribute
674
+ ` )
675
+
676
+ claimWithConstraintNotMatchingIntAttribute := unmarshal [resourceapi.ResourceClaim ](t , `
677
+ metadata:
678
+ name: claim
679
+ spec:
680
+ devices:
681
+ requests:
682
+ - name: req-0
683
+ countMode: Exact
684
+ count: 3
685
+ deviceClassName: driver-a
686
+ constraints:
687
+ - matchAttribute: numa
688
+ ` )
689
+
690
+ claimWithConstraintNotMatchingVersionAttribute := unmarshal [resourceapi.ResourceClaim ](t , `
691
+ metadata:
692
+ name: claim
693
+ spec:
694
+ devices:
695
+ requests:
696
+ - name: req-0
697
+ countMode: Exact
698
+ count: 3
699
+ deviceClassName: driver-a
700
+ constraints:
701
+ - matchAttribute: driverVersion
702
+ ` )
703
+
704
+ claimWithConstraintNotMatchingStringAttribute := unmarshal [resourceapi.ResourceClaim ](t , `
705
+ metadata:
706
+ name: claim
707
+ spec:
708
+ devices:
709
+ requests:
710
+ - name: req-0
711
+ countMode: Exact
712
+ count: 3
713
+ deviceClassName: driver-a
714
+ constraints:
715
+ - matchAttribute: stringAttribute
716
+ ` )
717
+
718
+ claimWithConstraintNotMatchingBoolAttribute := unmarshal [resourceapi.ResourceClaim ](t , `
719
+ metadata:
720
+ name: claim
721
+ spec:
722
+ devices:
723
+ requests:
724
+ - name: req-0
725
+ countMode: Exact
726
+ count: 3
727
+ deviceClassName: driver-a
728
+ constraints:
729
+ - matchAttribute: boolAttribute
730
+ ` )
731
+
610
732
fourDeviceClaim := unmarshal [resourceapi.ResourceClaim ](t , `
611
733
metadata:
612
734
name: claim
@@ -646,21 +768,7 @@ spec:
646
768
expression: device.capacity["driver-a"].memory.compareTo(quantity("1Gi")) >= 0
647
769
` )
648
770
649
- simpleClaimWithConstraint := unmarshal [resourceapi.ResourceClaim ](t , `
650
- metadata:
651
- name: claim
652
- spec:
653
- devices:
654
- requests:
655
- - name: req-0
656
- countMode: Exact
657
- count: 1
658
- deviceClassName: driver-a
659
- constraints:
660
- - matchAttribute: numa
661
- ` )
662
-
663
- simpleClaimWithConstraintUnsatisfiable := unmarshal [resourceapi.ResourceClaim ](t , `
771
+ simpleClaimWithConstraintNonExistentAttribute := unmarshal [resourceapi.ResourceClaim ](t , `
664
772
metadata:
665
773
name: claim
666
774
spec:
@@ -671,7 +779,7 @@ spec:
671
779
count: 1
672
780
deviceClassName: driver-a
673
781
constraints:
674
- - matchAttribute: doesnotexist
782
+ - matchAttribute: NonExistentAttribute
675
783
` )
676
784
677
785
allocatedTwoDeviceClaim := unmarshal [resourceapi.AllocationResult ](t , `
@@ -800,6 +908,24 @@ devices:
800
908
expectResults : nil ,
801
909
expectError : gomega .MatchError (gomega .ContainSubstring ("could not retrieve device class driver-a" )),
802
910
},
911
+ "unknown class" : {
912
+ claimsToAllocate : objects (simpleClaimWithUnknownClassName ),
913
+ classes : objects (driverAClass , driverBClass ),
914
+ slices : objects (node1slice , node1DriverBslice ),
915
+ node : node1 ,
916
+
917
+ expectResults : nil ,
918
+ expectError : gomega .MatchError (gomega .ContainSubstring ("could not retrieve device class unknown-class" )),
919
+ },
920
+ "empty class" : {
921
+ claimsToAllocate : objects (simpleClaimWithEmptyClassName ),
922
+ classes : objects (driverAClass , driverBClass ),
923
+ slices : objects (node1slice , node1DriverBslice ),
924
+ node : node1 ,
925
+
926
+ expectResults : nil ,
927
+ expectError : gomega .MatchError (gomega .ContainSubstring ("claim claim, request req-0: unsupported request type" )),
928
+ },
803
929
"no claims to allocate" : {
804
930
claimsToAllocate : nil ,
805
931
classes : objects (driverAClass ),
@@ -874,18 +1000,50 @@ devices:
874
1000
875
1001
expectResults : nil ,
876
1002
},
877
- "with constaint " : {
878
- claimsToAllocate : objects (simpleClaimWithConstraint ),
1003
+ "with constraint " : {
1004
+ claimsToAllocate : objects (twoDeviceClaimWithConstraint ),
879
1005
classes : objects (driverAClass ),
880
1006
slices : objects (node1slice ),
881
1007
node : node1 ,
882
1008
883
- expectResults : []any {allocatedSimpleClaim },
1009
+ expectResults : []any {allocatedTwoDeviceClaim },
884
1010
},
885
- "with unsatisfiable constaint " : {
886
- claimsToAllocate : objects (simpleClaimWithConstraintUnsatisfiable ),
1011
+ "with constraint: non-existent attribute " : {
1012
+ claimsToAllocate : objects (simpleClaimWithConstraintNonExistentAttribute ),
887
1013
classes : objects (driverAClass ),
888
- slices : objects (node1slice2 ),
1014
+ slices : objects (node1slice ),
1015
+ node : node1 ,
1016
+
1017
+ expectResults : nil ,
1018
+ },
1019
+ "with constraint: not matching int attribute" : {
1020
+ claimsToAllocate : objects (claimWithConstraintNotMatchingIntAttribute ),
1021
+ classes : objects (driverAClass , driverBClass ),
1022
+ slices : objects (node1slice , node1slice2 ),
1023
+ node : node1 ,
1024
+
1025
+ expectResults : nil ,
1026
+ },
1027
+ "with constraint: not matching version attribute" : {
1028
+ claimsToAllocate : objects (claimWithConstraintNotMatchingVersionAttribute ),
1029
+ classes : objects (driverAClass , driverBClass ),
1030
+ slices : objects (node1slice , node1slice2 ),
1031
+ node : node1 ,
1032
+
1033
+ expectResults : nil ,
1034
+ },
1035
+ "with constraint: not matching string attribute" : {
1036
+ claimsToAllocate : objects (claimWithConstraintNotMatchingStringAttribute ),
1037
+ classes : objects (driverAClass , driverBClass ),
1038
+ slices : objects (node1slice , node1slice2 ),
1039
+ node : node1 ,
1040
+
1041
+ expectResults : nil ,
1042
+ },
1043
+ "with constraint: not matching bool attribute" : {
1044
+ claimsToAllocate : objects (claimWithConstraintNotMatchingBoolAttribute ),
1045
+ classes : objects (driverAClass , driverBClass ),
1046
+ slices : objects (node1slice , node1slice2 ),
889
1047
node : node1 ,
890
1048
891
1049
expectResults : nil ,
0 commit comments