@@ -117,9 +117,17 @@ var (
117
117
Namespace (namespace ).
118
118
Request (className ).
119
119
Obj ()
120
+ claimWithPrioritzedList = st .MakeResourceClaim ().
121
+ Name (claimName ).
122
+ Namespace (namespace ).
123
+ RequestWithPrioritizedList (className ).
124
+ Obj ()
120
125
pendingClaim = st .FromResourceClaim (claim ).
121
126
OwnerReference (podName , podUID , podKind ).
122
127
Obj ()
128
+ pendingClaimWithPrioritizedList = st .FromResourceClaim (claimWithPrioritzedList ).
129
+ OwnerReference (podName , podUID , podKind ).
130
+ Obj ()
123
131
allocationResult = & resourceapi.AllocationResult {
124
132
Devices : resourceapi.DeviceAllocationResult {
125
133
Results : []resourceapi.DeviceRequestAllocationResult {{
@@ -133,13 +141,33 @@ var (
133
141
return st .MakeNodeSelector ().In ("metadata.name" , []string {nodeName }, st .NodeSelectorTypeMatchFields ).Obj ()
134
142
}(),
135
143
}
144
+ allocationResultWithPrioritizedList = & resourceapi.AllocationResult {
145
+ Devices : resourceapi.DeviceAllocationResult {
146
+ Results : []resourceapi.DeviceRequestAllocationResult {{
147
+ Driver : driver ,
148
+ Pool : nodeName ,
149
+ Device : "instance-1" ,
150
+ Request : "req-1/subreq-1" ,
151
+ }},
152
+ },
153
+ NodeSelector : func () * v1.NodeSelector {
154
+ return st .MakeNodeSelector ().In ("metadata.name" , []string {nodeName }, st .NodeSelectorTypeMatchFields ).Obj ()
155
+ }(),
156
+ }
136
157
inUseClaim = st .FromResourceClaim (pendingClaim ).
137
158
Allocation (allocationResult ).
138
159
ReservedForPod (podName , types .UID (podUID )).
139
160
Obj ()
161
+ inUseClaimWithPrioritizedList = st .FromResourceClaim (pendingClaimWithPrioritizedList ).
162
+ Allocation (allocationResultWithPrioritizedList ).
163
+ ReservedForPod (podName , types .UID (podUID )).
164
+ Obj ()
140
165
allocatedClaim = st .FromResourceClaim (pendingClaim ).
141
166
Allocation (allocationResult ).
142
167
Obj ()
168
+ allocatedClaimWithPrioritizedList = st .FromResourceClaim (pendingClaimWithPrioritizedList ).
169
+ Allocation (allocationResultWithPrioritizedList ).
170
+ Obj ()
143
171
144
172
allocatedClaimWithWrongTopology = st .FromResourceClaim (allocatedClaim ).
145
173
Allocation (& resourceapi.AllocationResult {NodeSelector : st .MakeNodeSelector ().In ("no-such-label" , []string {"no-such-value" }, st .NodeSelectorTypeMatchExpressions ).Obj ()}).
@@ -201,6 +229,24 @@ func breakCELInClass(class *resourceapi.DeviceClass) *resourceapi.DeviceClass {
201
229
return class
202
230
}
203
231
232
+ func updateDeviceClassName (claim * resourceapi.ResourceClaim , deviceClassName string ) * resourceapi.ResourceClaim {
233
+ claim = claim .DeepCopy ()
234
+ for i := range claim .Spec .Devices .Requests {
235
+ // If the firstAvailable list is empty we update the device class name
236
+ // on the base request.
237
+ if len (claim .Spec .Devices .Requests [i ].FirstAvailable ) == 0 {
238
+ claim .Spec .Devices .Requests [i ].DeviceClassName = deviceClassName
239
+ } else {
240
+ // If subrequests are specified, update the device class name on
241
+ // all of them.
242
+ for j := range claim .Spec .Devices .Requests [i ].FirstAvailable {
243
+ claim .Spec .Devices .Requests [i ].FirstAvailable [j ].DeviceClassName = deviceClassName
244
+ }
245
+ }
246
+ }
247
+ return claim
248
+ }
249
+
204
250
// result defines the expected outcome of some operation. It covers
205
251
// operation's status and the state of the world (= objects).
206
252
type result struct {
@@ -295,6 +341,8 @@ func TestPlugin(t *testing.T) {
295
341
// Feature gates. False is chosen so that the uncommon case
296
342
// doesn't need to be set.
297
343
disableDRA bool
344
+
345
+ enableDRAPrioritizedList bool
298
346
}{
299
347
"empty" : {
300
348
pod : st .MakePod ().Name ("foo" ).Namespace ("default" ).Obj (),
@@ -795,6 +843,69 @@ func TestPlugin(t *testing.T) {
795
843
},
796
844
disableDRA : true ,
797
845
},
846
+ "claim-with-request-with-unknown-device-class" : {
847
+ pod : podWithClaimName ,
848
+ claims : []* resourceapi.ResourceClaim {updateDeviceClassName (claim , "does-not-exist" )},
849
+ want : want {
850
+ prefilter : result {
851
+ status : framework .NewStatus (framework .Unschedulable , `request req-1: device class does-not-exist does not exist` ),
852
+ },
853
+ postfilter : result {
854
+ status : framework .NewStatus (framework .Unschedulable , `no new claims to deallocate` ),
855
+ },
856
+ },
857
+ },
858
+ "claim-with-prioritized-list-feature-disabled" : {
859
+ enableDRAPrioritizedList : false ,
860
+ pod : podWithClaimName ,
861
+ claims : []* resourceapi.ResourceClaim {claimWithPrioritzedList },
862
+ classes : []* resourceapi.DeviceClass {deviceClass },
863
+ want : want {
864
+ filter : perNodeResult {
865
+ workerNode .Name : {
866
+ status : framework .NewStatus (framework .UnschedulableAndUnresolvable , `claim default/my-pod-my-resource, request req-1: has subrequests, but the feature is disabled` ),
867
+ },
868
+ },
869
+ },
870
+ },
871
+ "claim-with-prioritized-list-unknown-device-class" : {
872
+ enableDRAPrioritizedList : true ,
873
+ pod : podWithClaimName ,
874
+ claims : []* resourceapi.ResourceClaim {updateDeviceClassName (claimWithPrioritzedList , "does-not-exist" )},
875
+ want : want {
876
+ prefilter : result {
877
+ status : framework .NewStatus (framework .Unschedulable , `request req-1/subreq-1: device class does-not-exist does not exist` ),
878
+ },
879
+ postfilter : result {
880
+ status : framework .NewStatus (framework .Unschedulable , `no new claims to deallocate` ),
881
+ },
882
+ },
883
+ },
884
+ "claim-with-prioritized-list" : {
885
+ enableDRAPrioritizedList : true ,
886
+ pod : podWithClaimName ,
887
+ claims : []* resourceapi.ResourceClaim {pendingClaimWithPrioritizedList },
888
+ classes : []* resourceapi.DeviceClass {deviceClass },
889
+ objs : []apiruntime.Object {workerNodeSlice },
890
+ want : want {
891
+ reserve : result {
892
+ inFlightClaim : allocatedClaimWithPrioritizedList ,
893
+ },
894
+ prebind : result {
895
+ assumedClaim : reserve (allocatedClaimWithPrioritizedList , podWithClaimName ),
896
+ changes : change {
897
+ claim : func (claim * resourceapi.ResourceClaim ) * resourceapi.ResourceClaim {
898
+ if claim .Name == claimName {
899
+ claim = claim .DeepCopy ()
900
+ claim .Finalizers = allocatedClaimWithPrioritizedList .Finalizers
901
+ claim .Status = inUseClaimWithPrioritizedList .Status
902
+ }
903
+ return claim
904
+ },
905
+ },
906
+ },
907
+ },
908
+ },
798
909
}
799
910
800
911
for name , tc := range testcases {
@@ -809,6 +920,7 @@ func TestPlugin(t *testing.T) {
809
920
features := feature.Features {
810
921
EnableDRAAdminAccess : tc .enableDRAAdminAccess ,
811
922
EnableDynamicResourceAllocation : ! tc .disableDRA ,
923
+ EnableDRAPrioritizedList : tc .enableDRAPrioritizedList ,
812
924
}
813
925
testCtx := setup (t , nodes , tc .claims , tc .classes , tc .objs , features )
814
926
initialObjects := testCtx .listAll (t )
0 commit comments