@@ -31,6 +31,7 @@ import (
3131 "github.com/onsi/gomega"
3232 v1 "k8s.io/api/core/v1"
3333 resourcev1 "k8s.io/api/resource/v1"
34+ "k8s.io/apimachinery/pkg/api/resource"
3435 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3536 "k8s.io/utils/cpuset"
3637)
@@ -233,6 +234,65 @@ var _ = ginkgo.Describe("CPU Allocation", ginkgo.Serial, ginkgo.Ordered, ginkgo.
233234 verifySharedPoolMatches (ctx , fxt , shrPod1 , availableCPUs )
234235 verifySharedPoolMatches (ctx , fxt , shrPod2 , availableCPUs )
235236 })
237+
238+ ginkgo .It ("should allocate non-overlapping CPUs for multiple requests in the same grouped claim" , func (ctx context.Context ) {
239+ if cpuDeviceMode != "grouped" {
240+ ginkgo .Skip ("this test only applies to grouped CPU device mode" )
241+ }
242+ if availableCPUs .Size () < 2 {
243+ ginkgo .Skip ("need at least 2 available CPUs for this test" )
244+ }
245+
246+ fixture .By ("creating a ResourceClaim with two requests each asking for 1 CPU" )
247+ cpuClaim := & resourcev1.ResourceClaim {
248+ ObjectMeta : metav1.ObjectMeta {
249+ Namespace : fxt .Namespace .Name ,
250+ GenerateName : "claim-multi-request-" ,
251+ },
252+ Spec : resourcev1.ResourceClaimSpec {
253+ Devices : resourcev1.DeviceClaim {
254+ Requests : []resourcev1.DeviceRequest {
255+ {
256+ Name : "request-0" ,
257+ Exactly : & resourcev1.ExactDeviceRequest {
258+ DeviceClassName : "dra.cpu" ,
259+ Capacity : & resourcev1.CapacityRequirements {
260+ Requests : map [resourcev1.QualifiedName ]resource.Quantity {
261+ "dra.cpu/cpu" : * resource .NewQuantity (1 , resource .DecimalSI ),
262+ },
263+ },
264+ },
265+ },
266+ {
267+ Name : "request-1" ,
268+ Exactly : & resourcev1.ExactDeviceRequest {
269+ DeviceClassName : "dra.cpu" ,
270+ Capacity : & resourcev1.CapacityRequirements {
271+ Requests : map [resourcev1.QualifiedName ]resource.Quantity {
272+ "dra.cpu/cpu" : * resource .NewQuantity (1 , resource .DecimalSI ),
273+ },
274+ },
275+ },
276+ },
277+ },
278+ },
279+ },
280+ }
281+ createdClaim , err := fxt .K8SClientset .ResourceV1 ().ResourceClaims (fxt .Namespace .Name ).Create (ctx , cpuClaim , metav1.CreateOptions {})
282+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
283+
284+ fixture .By ("creating a pod consuming the multi-request claim" )
285+ pod := makeTesterPodWithNamedClaim (fxt .Namespace .Name , dracpuTesterImage , createdClaim .Name , targetNode .Name )
286+ createdPod , err := e2epod .CreateSync (ctx , fxt .K8SClientset , pod )
287+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
288+
289+ fixture .By ("verifying the pod got 2 distinct CPUs with no overlap" )
290+ alloc := getTesterPodCPUAllocation (fxt .K8SClientset , ctx , createdPod )
291+ fxt .Log .Info ("multi-request claim allocation" , "cpuAssigned" , alloc .CPUAssigned .String ())
292+ gomega .Expect (alloc .CPUAssigned .Size ()).To (gomega .Equal (2 ), "expected 2 distinct CPUs allocated" )
293+ gomega .Expect (alloc .CPUAssigned .IsSubsetOf (availableCPUs )).To (gomega .BeTrue (), "allocated CPUs must be within available set" )
294+
295+ })
236296 })
237297 })
238298})
0 commit comments