fix kubelet crash, concurrent map iteration and map write

When kubelet starts a Pod that requires device resources, if the device
plug-in updates the device at the same time, it may cause kubelet to crash.

Signed-off-by: huyinhou <huyinhou@bytedance.com>
This commit is contained in:
huyinhou 2022-12-19 12:07:10 +08:00
parent 789dc88fd5
commit 692f8aab27

View File

@ -147,11 +147,15 @@ func (m *ManagerImpl) deviceHasTopologyAlignment(resource string) bool {
}
func (m *ManagerImpl) getAvailableDevices(resource string) sets.String {
m.mutex.Lock()
defer m.mutex.Unlock()
// Strip all devices in use from the list of healthy ones.
return m.healthyDevices[resource].Difference(m.allocatedDevices[resource])
}
func (m *ManagerImpl) generateDeviceTopologyHints(resource string, available sets.String, reusable sets.String, request int) []topologymanager.TopologyHint {
m.mutex.Lock()
defer m.mutex.Unlock()
// Initialize minAffinitySize to include all NUMA Nodes
minAffinitySize := len(m.numaNodes)