Skip to content

Commit abf87c9

Browse files
committed
Add GetPreferredAllocation() as a supported device plugin endpoint
1 parent 32c047a commit abf87c9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/kubelet/cm/devicemanager/endpoint.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
type endpoint interface {
3636
run()
3737
stop()
38+
getPreferredAllocation(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error)
3839
allocate(devs []string) (*pluginapi.AllocateResponse, error)
3940
preStartContainer(devs []string) (*pluginapi.PreStartContainerResponse, error)
4041
callback(resourceName string, devices []pluginapi.Device)
@@ -138,6 +139,22 @@ func (e *endpointImpl) setStopTime(t time.Time) {
138139
e.stopTime = t
139140
}
140141

142+
// getPreferredAllocation issues GetPreferredAllocation gRPC call to the device plugin.
143+
func (e *endpointImpl) getPreferredAllocation(available, mustInclude []string, size int) (*pluginapi.PreferredAllocationResponse, error) {
144+
if e.isStopped() {
145+
return nil, fmt.Errorf(errEndpointStopped, e)
146+
}
147+
return e.client.GetPreferredAllocation(context.Background(), &pluginapi.PreferredAllocationRequest{
148+
ContainerRequests: []*pluginapi.ContainerPreferredAllocationRequest{
149+
{
150+
AvailableDeviceIDs: available,
151+
MustIncludeDeviceIDs: mustInclude,
152+
AllocationSize: int32(size),
153+
},
154+
},
155+
})
156+
}
157+
141158
// allocate issues Allocate gRPC call to the device plugin.
142159
func (e *endpointImpl) allocate(devs []string) (*pluginapi.AllocateResponse, error) {
143160
if e.isStopped() {

0 commit comments

Comments
 (0)