@@ -51,27 +51,30 @@ type devicePluginServer interface {
5151
5252// server implements devicePluginServer and pluginapi.PluginInterfaceServer interfaces.
5353type server struct {
54- devType string
55- grpcServer * grpc.Server
56- updatesCh chan map [string ]DeviceInfo
57- devices map [string ]DeviceInfo
58- postAllocate func (* pluginapi.AllocateResponse ) error
59- preStartContainer func (* pluginapi.PreStartContainerRequest ) error
60- state serverState
61- stateMutex sync.Mutex
54+ devType string
55+ grpcServer * grpc.Server
56+ updatesCh chan map [string ]DeviceInfo
57+ devices map [string ]DeviceInfo
58+ postAllocate postAllocateFunc
59+ preStartContainer preStartContainerFunc
60+ getPreferredAllocation getPreferredAllocationFunc
61+ state serverState
62+ stateMutex sync.Mutex
6263}
6364
6465// newServer creates a new server satisfying the devicePluginServer interface.
6566func newServer (devType string ,
66- postAllocate func (* pluginapi.AllocateResponse ) error ,
67- preStartContainer func (* pluginapi.PreStartContainerRequest ) error ) devicePluginServer {
67+ postAllocate postAllocateFunc ,
68+ preStartContainer preStartContainerFunc ,
69+ getPreferredAllocation getPreferredAllocationFunc ) devicePluginServer {
6870 return & server {
69- devType : devType ,
70- updatesCh : make (chan map [string ]DeviceInfo , 1 ), // TODO: is 1 needed?
71- devices : make (map [string ]DeviceInfo ),
72- postAllocate : postAllocate ,
73- preStartContainer : preStartContainer ,
74- state : uninitialized ,
71+ devType : devType ,
72+ updatesCh : make (chan map [string ]DeviceInfo , 1 ), // TODO: is 1 needed?
73+ devices : make (map [string ]DeviceInfo ),
74+ postAllocate : postAllocate ,
75+ preStartContainer : preStartContainer ,
76+ getPreferredAllocation : getPreferredAllocation ,
77+ state : uninitialized ,
7578 }
7679}
7780
@@ -162,6 +165,9 @@ func (srv *server) PreStartContainer(ctx context.Context, rqt *pluginapi.PreStar
162165}
163166
164167func (srv * server ) GetPreferredAllocation (ctx context.Context , rqt * pluginapi.PreferredAllocationRequest ) (* pluginapi.PreferredAllocationResponse , error ) {
168+ if srv .getPreferredAllocation != nil {
169+ return srv .getPreferredAllocation (rqt )
170+ }
165171 return nil , errors .New ("GetPreferredAllocation should not be called as this device plugin doesn't implement it" )
166172}
167173
0 commit comments