From abf87c99c63984ba426239e0aed657bf9a8a9054 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Thu, 2 Jul 2020 15:15:50 +0000 Subject: [PATCH] Add GetPreferredAllocation() as a supported device plugin endpoint --- pkg/kubelet/cm/devicemanager/endpoint.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/kubelet/cm/devicemanager/endpoint.go b/pkg/kubelet/cm/devicemanager/endpoint.go index 18b212733dd..eaef0df39aa 100644 --- a/pkg/kubelet/cm/devicemanager/endpoint.go +++ b/pkg/kubelet/cm/devicemanager/endpoint.go @@ -35,6 +35,7 @@ import ( type endpoint interface { run() stop() + getPreferredAllocation(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error) allocate(devs []string) (*pluginapi.AllocateResponse, error) preStartContainer(devs []string) (*pluginapi.PreStartContainerResponse, error) callback(resourceName string, devices []pluginapi.Device) @@ -138,6 +139,22 @@ func (e *endpointImpl) setStopTime(t time.Time) { e.stopTime = t } +// getPreferredAllocation issues GetPreferredAllocation gRPC call to the device plugin. +func (e *endpointImpl) getPreferredAllocation(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error) { + if e.isStopped() { + return nil, fmt.Errorf(errEndpointStopped, e) + } + return e.client.GetPreferredAllocation(context.Background(), &pluginapi.PreferredAllocationRequest{ + ContainerRequests: []*pluginapi.ContainerPreferredAllocationRequest{ + { + AvailableDeviceIDs: available, + MustIncludeDeviceIDs: mustInclude, + AllocationSize: int32(size), + }, + }, + }) +} + // allocate issues Allocate gRPC call to the device plugin. func (e *endpointImpl) allocate(devs []string) (*pluginapi.AllocateResponse, error) { if e.isStopped() {