in plugins/internal/plugin/device_plugin.go [368:399]
func (p *DevicePlugin) Allocate(ctx context.Context, request *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
p.logger.Infow("Allocate RPC invoked, processing allocation request", "request", request)
response := &pluginapi.AllocateResponse{}
// Process each of the container requests
for _, containerReq := range request.ContainerRequests {
// Gather the list of requested devices for the container
devices := []*discovery.Device{}
for _, deviceID := range containerReq.DevicesIDs {
// Verify that the requested device exists
device, err := p.GetDeviceForID(deviceID)
if err != nil {
return nil, err
}
// Add the device to the list
devices = append(devices, device)
}
// Generate the device specs and runtime file mounts for the requested devices, appending the container response to our overall response
response.ContainerResponses = append(response.ContainerResponses, &pluginapi.ContainerAllocateResponse{
Devices: mount.SpecsForDevices(devices),
Mounts: mount.MountsForDevices(devices),
})
}
p.logger.Infow("Sending allocation response", "response", response)
return response, nil
}