Skip to content

Commit bb56a09

Browse files
committed
Add callGetPreferredAllocationIfAvailable() function in devicemanager
This function mimics what is already done for the conditional call to PreStartContainer() via the callPreStartContainerIfNeeded() function.
1 parent abf87c9 commit bb56a09

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pkg/kubelet/cm/devicemanager/manager.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,30 @@ func (m *ManagerImpl) callPreStartContainerIfNeeded(podUID, contName, resource s
921921
return nil
922922
}
923923

924+
// callGetPreferredAllocationIfAvailable issues GetPreferredAllocation grpc
925+
// call for device plugin resource with GetPreferredAllocationAvailable option set.
926+
func (m *ManagerImpl) callGetPreferredAllocationIfAvailable(podUID, contName, resource string, available, mustInclude sets.String, size int) (sets.String, error) {
927+
eI, ok := m.endpoints[resource]
928+
if !ok {
929+
return nil, fmt.Errorf("endpoint not found in cache for a registered resource: %s", resource)
930+
}
931+
932+
if eI.opts == nil || !eI.opts.GetPreferredAllocationAvailable {
933+
klog.V(4).Infof("Plugin options indicate to skip GetPreferredAllocation for resource: %s", resource)
934+
return nil, nil
935+
}
936+
937+
m.mutex.Unlock()
938+
klog.V(4).Infof("Issuing a GetPreferredAllocation call for container, %s, of pod %s", contName, podUID)
939+
resp, err := eI.e.getPreferredAllocation(available.UnsortedList(), mustInclude.UnsortedList(), size)
940+
m.mutex.Lock()
941+
if err != nil {
942+
return nil, fmt.Errorf("device plugin GetPreferredAllocation rpc failed with err: %v", err)
943+
}
944+
// TODO: Add metrics support for init RPC
945+
return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil
946+
}
947+
924948
// sanitizeNodeAllocatable scans through allocatedDevices in the device manager
925949
// and if necessary, updates allocatableResource in nodeInfo to at least equal to
926950
// the allocated capacity. This allows pods that have already been scheduled on

0 commit comments

Comments
 (0)