mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	DRA API: AdminAccess in DeviceRequestAllocationResult
Drivers need to know that because admin access may also grant additional permissions. The allocator needs to ignore such results when determining which devices are considered as allocated. In both cases it is conceptually cleaner to not rely on the content of the ClaimSpec.
This commit is contained in:
		@@ -135,10 +135,11 @@ var (
 | 
			
		||||
	allocationResult = &resourceapi.AllocationResult{
 | 
			
		||||
		Devices: resourceapi.DeviceAllocationResult{
 | 
			
		||||
			Results: []resourceapi.DeviceRequestAllocationResult{{
 | 
			
		||||
				Driver:  driver,
 | 
			
		||||
				Pool:    nodeName,
 | 
			
		||||
				Device:  "instance-1",
 | 
			
		||||
				Request: "req-1",
 | 
			
		||||
				Driver:      driver,
 | 
			
		||||
				Pool:        nodeName,
 | 
			
		||||
				Device:      "instance-1",
 | 
			
		||||
				Request:     "req-1",
 | 
			
		||||
				AdminAccess: ptr.To(false),
 | 
			
		||||
			}},
 | 
			
		||||
		},
 | 
			
		||||
		NodeSelector: func() *v1.NodeSelector {
 | 
			
		||||
@@ -178,6 +179,19 @@ func reserve(claim *resourceapi.ResourceClaim, pod *v1.Pod) *resourceapi.Resourc
 | 
			
		||||
		Obj()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func adminAccess(claim *resourceapi.ResourceClaim) *resourceapi.ResourceClaim {
 | 
			
		||||
	claim = claim.DeepCopy()
 | 
			
		||||
	for i := range claim.Spec.Devices.Requests {
 | 
			
		||||
		claim.Spec.Devices.Requests[i].AdminAccess = true
 | 
			
		||||
	}
 | 
			
		||||
	if claim.Status.Allocation != nil {
 | 
			
		||||
		for i := range claim.Status.Allocation.Devices.Results {
 | 
			
		||||
			claim.Status.Allocation.Devices.Results[i].AdminAccess = ptr.To(true)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return claim
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func breakCELInClaim(claim *resourceapi.ResourceClaim) *resourceapi.ResourceClaim {
 | 
			
		||||
	claim = claim.DeepCopy()
 | 
			
		||||
	for i := range claim.Spec.Devices.Requests {
 | 
			
		||||
@@ -556,6 +570,66 @@ func TestPlugin(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		"request-admin-access": {
 | 
			
		||||
			// Because the pending claim asks for admin access, allocation succeeds despite resources
 | 
			
		||||
			// being exhausted.
 | 
			
		||||
			pod:     podWithClaimName,
 | 
			
		||||
			claims:  []*resourceapi.ResourceClaim{adminAccess(pendingClaim), otherAllocatedClaim},
 | 
			
		||||
			classes: []*resourceapi.DeviceClass{deviceClass},
 | 
			
		||||
			objs:    []apiruntime.Object{workerNodeSlice},
 | 
			
		||||
			want: want{
 | 
			
		||||
				reserve: result{
 | 
			
		||||
					inFlightClaim: adminAccess(allocatedClaim),
 | 
			
		||||
				},
 | 
			
		||||
				prebind: result{
 | 
			
		||||
					assumedClaim: reserve(adminAccess(allocatedClaim), podWithClaimName),
 | 
			
		||||
					changes: change{
 | 
			
		||||
						claim: func(claim *resourceapi.ResourceClaim) *resourceapi.ResourceClaim {
 | 
			
		||||
							if claim.Name == claimName {
 | 
			
		||||
								claim = claim.DeepCopy()
 | 
			
		||||
								claim.Finalizers = allocatedClaim.Finalizers
 | 
			
		||||
								claim.Status = adminAccess(inUseClaim).Status
 | 
			
		||||
							}
 | 
			
		||||
							return claim
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				postbind: result{
 | 
			
		||||
					assumedClaim: reserve(adminAccess(allocatedClaim), podWithClaimName),
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		"structured-ignore-allocated-admin-access": {
 | 
			
		||||
			// The allocated claim uses admin access, so a second claim may use
 | 
			
		||||
			// the same device.
 | 
			
		||||
			pod:     podWithClaimName,
 | 
			
		||||
			claims:  []*resourceapi.ResourceClaim{pendingClaim, adminAccess(otherAllocatedClaim)},
 | 
			
		||||
			classes: []*resourceapi.DeviceClass{deviceClass},
 | 
			
		||||
			objs:    []apiruntime.Object{workerNodeSlice},
 | 
			
		||||
			want: want{
 | 
			
		||||
				reserve: result{
 | 
			
		||||
					inFlightClaim: allocatedClaim,
 | 
			
		||||
				},
 | 
			
		||||
				prebind: result{
 | 
			
		||||
					assumedClaim: reserve(allocatedClaim, podWithClaimName),
 | 
			
		||||
					changes: change{
 | 
			
		||||
						claim: func(claim *resourceapi.ResourceClaim) *resourceapi.ResourceClaim {
 | 
			
		||||
							if claim.Name == claimName {
 | 
			
		||||
								claim = claim.DeepCopy()
 | 
			
		||||
								claim.Finalizers = allocatedClaim.Finalizers
 | 
			
		||||
								claim.Status = inUseClaim.Status
 | 
			
		||||
							}
 | 
			
		||||
							return claim
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				postbind: result{
 | 
			
		||||
					assumedClaim: reserve(allocatedClaim, podWithClaimName),
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		"claim-parameters-CEL-runtime-error": {
 | 
			
		||||
			pod:     podWithClaimName,
 | 
			
		||||
			claims:  []*resourceapi.ResourceClaim{breakCELInClaim(pendingClaim)},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user