From bb56a09133c91ceb1745e9267112c9f4ec37ceff Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Thu, 2 Jul 2020 15:15:53 +0000 Subject: [PATCH] Add callGetPreferredAllocationIfAvailable() function in devicemanager This function mimics what is already done for the conditional call to PreStartContainer() via the callPreStartContainerIfNeeded() function. --- pkg/kubelet/cm/devicemanager/manager.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/kubelet/cm/devicemanager/manager.go b/pkg/kubelet/cm/devicemanager/manager.go index 983576eb242..90aafb5c54b 100644 --- a/pkg/kubelet/cm/devicemanager/manager.go +++ b/pkg/kubelet/cm/devicemanager/manager.go @@ -921,6 +921,30 @@ func (m *ManagerImpl) callPreStartContainerIfNeeded(podUID, contName, resource s return nil } +// callGetPreferredAllocationIfAvailable issues GetPreferredAllocation grpc +// call for device plugin resource with GetPreferredAllocationAvailable option set. +func (m *ManagerImpl) callGetPreferredAllocationIfAvailable(podUID, contName, resource string, available, mustInclude sets.String, size int) (sets.String, error) { + eI, ok := m.endpoints[resource] + if !ok { + return nil, fmt.Errorf("endpoint not found in cache for a registered resource: %s", resource) + } + + if eI.opts == nil || !eI.opts.GetPreferredAllocationAvailable { + klog.V(4).Infof("Plugin options indicate to skip GetPreferredAllocation for resource: %s", resource) + return nil, nil + } + + m.mutex.Unlock() + klog.V(4).Infof("Issuing a GetPreferredAllocation call for container, %s, of pod %s", contName, podUID) + resp, err := eI.e.getPreferredAllocation(available.UnsortedList(), mustInclude.UnsortedList(), size) + m.mutex.Lock() + if err != nil { + return nil, fmt.Errorf("device plugin GetPreferredAllocation rpc failed with err: %v", err) + } + // TODO: Add metrics support for init RPC + return sets.NewString(resp.ContainerResponses[0].DeviceIDs...), nil +} + // sanitizeNodeAllocatable scans through allocatedDevices in the device manager // and if necessary, updates allocatableResource in nodeInfo to at least equal to // the allocated capacity. This allows pods that have already been scheduled on