type ClaimLister … type Allocator … // NewAllocator returns an allocator for a certain set of claims or an error if // some problem was detected which makes it impossible to allocate claims. func NewAllocator(ctx context.Context, adminAccessEnabled bool, claimsToAllocate []*resourceapi.ResourceClaim, claimLister ClaimLister, classLister resourcelisters.DeviceClassLister, sliceLister resourcelisters.ResourceSliceLister, ) (*Allocator, error) { … } // ClaimsToAllocate returns the claims that the allocator was created for. func (a *Allocator) ClaimsToAllocate() []*resourceapi.ResourceClaim { … } // Allocate calculates the allocation(s) for one particular node. // // It returns an error only if some fatal problem occurred. These are errors // caused by invalid input data, like for example errors in CEL selectors, so a // scheduler should abort and report that problem instead of trying to find // other nodes where the error doesn't occur. // // In the future, special errors will be defined which enable the caller to // identify which object (like claim or class) caused the problem. This will // enable reporting the problem as event for those objects. // // If the claims cannot be allocated, it returns nil. This includes the // situation where the resource slices are incomplete at the moment. // // If the claims can be allocated, then it prepares one allocation result for // each unallocated claim. It is the responsibility of the caller to persist // those allocations, if desired. // // Allocate is thread-safe. If the caller wants to get the node name included // in log output, it can use contextual logging and add the node as an // additional value. A name can also be useful because log messages do not // have a common prefix. V(5) is used for one-time log entries, V(6) for important // progress reports, and V(7) for detailed debug output. func (a *Allocator) Allocate(ctx context.Context, node *v1.Node) (finalResult []*resourceapi.AllocationResult, finalErr error) { … } var errStop … type allocator … type matchKey … type requestIndices … type deviceIndices … type requestData … type deviceWithID … type constraint … type matchAttributeConstraint … func (m *matchAttributeConstraint) add(requestName string, device *resourceapi.BasicDevice, deviceID DeviceID) bool { … } func (m *matchAttributeConstraint) remove(requestName string, device *resourceapi.BasicDevice, deviceID DeviceID) { … } func lookupAttribute(device *resourceapi.BasicDevice, deviceID DeviceID, attributeName resourceapi.FullyQualifiedName) *resourceapi.DeviceAttribute { … } // allocateOne iterates over all eligible devices (not in use, match selector, // satisfy constraints) for a specific required device. It returns true if // everything got allocated, an error if allocation needs to stop. func (alloc *allocator) allocateOne(r deviceIndices) (bool, error) { … } // isSelectable checks whether a device satisfies the request and class selectors. func (alloc *allocator) isSelectable(r requestIndices, slice *resourceapi.ResourceSlice, deviceIndex int) (bool, error) { … } func (alloc *allocator) selectorsMatch(r requestIndices, device *resourceapi.BasicDevice, deviceID DeviceID, class *resourceapi.DeviceClass, selectors []resourceapi.DeviceSelector) (bool, error) { … } // allocateDevice checks device availability and constraints for one // candidate. The device must be selectable. // // If that candidate works out okay, the shared state gets updated // as if that candidate had been allocated. If allocation cannot continue later // and must try something else, then the rollback function can be invoked to // restore the previous state. func (alloc *allocator) allocateDevice(r deviceIndices, device *resourceapi.BasicDevice, deviceID DeviceID, must bool) (bool, func(), error) { … } // createNodeSelector constructs a node selector for the allocation, if needed, // otherwise it returns nil. func (alloc *allocator) createNodeSelector(allocation *resourceapi.AllocationResult) (*v1.NodeSelector, error) { … } func (alloc *allocator) findSlice(deviceAllocation resourceapi.DeviceRequestAllocationResult) *resourceapi.ResourceSlice { … } func addNewNodeSelectorRequirements(from []v1.NodeSelectorRequirement, to *[]v1.NodeSelectorRequirement) { … } func containsNodeSelectorRequirement(requirements []v1.NodeSelectorRequirement, requirement v1.NodeSelectorRequirement) bool { … }