Skip to content

Commit 5a5724d

Browse files
committed
DRA: add even more allocator test cases
1 parent d360839 commit 5a5724d

File tree

1 file changed

+186
-28
lines changed

1 file changed

+186
-28
lines changed

staging/src/k8s.io/dynamic-resource-allocation/structured/allocator_test.go

Lines changed: 186 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ func TestAllocator(t *testing.T) {
200200
// },
201201
// },
202202
// }
203+
204+
// Slices
205+
203206
node1slice := unmarshal[resourceapi.ResourceSlice](t, `
204207
metadata:
205208
name: worker-1-slice
@@ -218,6 +221,10 @@ spec:
218221
version: 1.0.0
219222
numa:
220223
int: 1
224+
stringAttribute:
225+
string: stringAttributeValue
226+
boolAttribute:
227+
bool: true
221228
capacity:
222229
memory: 1Gi # small
223230
- name: device-2
@@ -227,6 +234,10 @@ spec:
227234
version: 1.0.0
228235
numa:
229236
int: 1
237+
stringAttribute:
238+
string: stringAttributeValue
239+
boolAttribute:
240+
bool: true
230241
capacity:
231242
memory: 2Gi # large
232243
`)
@@ -247,18 +258,26 @@ spec:
247258
basic:
248259
attributes:
249260
driverVersion:
250-
version: 1.0.0
261+
version: 2.0.0
251262
numa:
252-
int: 1
263+
int: 2
264+
stringAttribute:
265+
string: stringAttributeValue2
266+
boolAttribute:
267+
bool: false
253268
capacity:
254269
memory: 1Gi # small
255270
- name: device-6
256271
basic:
257272
attributes:
258273
driverVersion:
259-
version: 1.0.0
274+
version: 2.0.0
260275
numa:
261-
int: 1
276+
int: 2
277+
stringAttribute:
278+
string: stringAttributeValue2
279+
boolAttribute:
280+
bool: false
262281
capacity:
263282
memory: 2Gi # large
264283
`)
@@ -424,7 +443,7 @@ spec:
424443
basic:
425444
attributes:
426445
driverVersion:
427-
version: 1.0.0
446+
version: 2.0.0
428447
numa:
429448
int: 1
430449
capacity:
@@ -433,13 +452,15 @@ spec:
433452
basic:
434453
attributes:
435454
driverVersion:
436-
version: 1.0.0
455+
version: 2.0.0
437456
numa:
438457
int: 1
439458
capacity:
440459
memory: 2Gi # large
441460
`)
442461

462+
// Claims
463+
443464
simpleClaim := unmarshal[resourceapi.ResourceClaim](t, `
444465
metadata:
445466
name: claim
@@ -480,6 +501,30 @@ spec:
480501
parameters: {"deviceAttribute":"deviceAttributeValue"}
481502
`)
482503

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+
483528
allocatedSimpleClaim := unmarshal[resourceapi.AllocationResult](t, `
484529
devices:
485530
results:
@@ -607,6 +652,83 @@ spec:
607652
expression: device.capacity["driver-a"].memory.compareTo(quantity("2Gi")) >= 0
608653
`)
609654

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+
610732
fourDeviceClaim := unmarshal[resourceapi.ResourceClaim](t, `
611733
metadata:
612734
name: claim
@@ -646,21 +768,7 @@ spec:
646768
expression: device.capacity["driver-a"].memory.compareTo(quantity("1Gi")) >= 0
647769
`)
648770

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, `
664772
metadata:
665773
name: claim
666774
spec:
@@ -671,7 +779,7 @@ spec:
671779
count: 1
672780
deviceClassName: driver-a
673781
constraints:
674-
- matchAttribute: doesnotexist
782+
- matchAttribute: NonExistentAttribute
675783
`)
676784

677785
allocatedTwoDeviceClaim := unmarshal[resourceapi.AllocationResult](t, `
@@ -800,6 +908,24 @@ devices:
800908
expectResults: nil,
801909
expectError: gomega.MatchError(gomega.ContainSubstring("could not retrieve device class driver-a")),
802910
},
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+
},
803929
"no claims to allocate": {
804930
claimsToAllocate: nil,
805931
classes: objects(driverAClass),
@@ -874,18 +1000,50 @@ devices:
8741000

8751001
expectResults: nil,
8761002
},
877-
"with constaint": {
878-
claimsToAllocate: objects(simpleClaimWithConstraint),
1003+
"with constraint": {
1004+
claimsToAllocate: objects(twoDeviceClaimWithConstraint),
8791005
classes: objects(driverAClass),
8801006
slices: objects(node1slice),
8811007
node: node1,
8821008

883-
expectResults: []any{allocatedSimpleClaim},
1009+
expectResults: []any{allocatedTwoDeviceClaim},
8841010
},
885-
"with unsatisfiable constaint": {
886-
claimsToAllocate: objects(simpleClaimWithConstraintUnsatisfiable),
1011+
"with constraint: non-existent attribute": {
1012+
claimsToAllocate: objects(simpleClaimWithConstraintNonExistentAttribute),
8871013
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),
8891047
node: node1,
8901048

8911049
expectResults: nil,

0 commit comments

Comments
 (0)