mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
device manager: do not clean admitted pods from the state
Signed-off-by: Artyom Lukianov <alukiano@redhat.com>
This commit is contained in:
parent
93a237abd8
commit
73a5cce3e6
@ -108,6 +108,9 @@ type ManagerImpl struct {
|
|||||||
// devicesToReuse contains devices that can be reused as they have been allocated to
|
// devicesToReuse contains devices that can be reused as they have been allocated to
|
||||||
// init containers.
|
// init containers.
|
||||||
devicesToReuse PodReusableDevices
|
devicesToReuse PodReusableDevices
|
||||||
|
|
||||||
|
// pendingAdmissionPod contain the pod during the admission phase
|
||||||
|
pendingAdmissionPod *v1.Pod
|
||||||
}
|
}
|
||||||
|
|
||||||
type endpointInfo struct {
|
type endpointInfo struct {
|
||||||
@ -367,6 +370,10 @@ func (m *ManagerImpl) isVersionCompatibleWithPlugin(versions []string) bool {
|
|||||||
// Allocate is the call that you can use to allocate a set of devices
|
// Allocate is the call that you can use to allocate a set of devices
|
||||||
// from the registered device plugins.
|
// from the registered device plugins.
|
||||||
func (m *ManagerImpl) Allocate(pod *v1.Pod, container *v1.Container) error {
|
func (m *ManagerImpl) Allocate(pod *v1.Pod, container *v1.Container) error {
|
||||||
|
// The pod is during the admission phase. We need to save the pod to avoid it
|
||||||
|
// being cleaned before the admission ended
|
||||||
|
m.setPodPendingAdmission(pod)
|
||||||
|
|
||||||
if _, ok := m.devicesToReuse[string(pod.UID)]; !ok {
|
if _, ok := m.devicesToReuse[string(pod.UID)]; !ok {
|
||||||
m.devicesToReuse[string(pod.UID)] = make(map[string]sets.String)
|
m.devicesToReuse[string(pod.UID)] = make(map[string]sets.String)
|
||||||
}
|
}
|
||||||
@ -619,14 +626,20 @@ func (m *ManagerImpl) readCheckpoint() error {
|
|||||||
|
|
||||||
// UpdateAllocatedDevices frees any Devices that are bound to terminated pods.
|
// UpdateAllocatedDevices frees any Devices that are bound to terminated pods.
|
||||||
func (m *ManagerImpl) UpdateAllocatedDevices() {
|
func (m *ManagerImpl) UpdateAllocatedDevices() {
|
||||||
activePods := m.activePods()
|
|
||||||
if !m.sourcesReady.AllReady() {
|
if !m.sourcesReady.AllReady() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.mutex.Lock()
|
m.mutex.Lock()
|
||||||
defer m.mutex.Unlock()
|
defer m.mutex.Unlock()
|
||||||
|
|
||||||
|
activeAndAdmittedPods := m.activePods()
|
||||||
|
if m.pendingAdmissionPod != nil {
|
||||||
|
activeAndAdmittedPods = append(activeAndAdmittedPods, m.pendingAdmissionPod)
|
||||||
|
}
|
||||||
|
|
||||||
podsToBeRemoved := m.podDevices.pods()
|
podsToBeRemoved := m.podDevices.pods()
|
||||||
for _, pod := range activePods {
|
for _, pod := range activeAndAdmittedPods {
|
||||||
podsToBeRemoved.Delete(string(pod.UID))
|
podsToBeRemoved.Delete(string(pod.UID))
|
||||||
}
|
}
|
||||||
if len(podsToBeRemoved) <= 0 {
|
if len(podsToBeRemoved) <= 0 {
|
||||||
@ -1117,3 +1130,10 @@ func (m *ManagerImpl) ShouldResetExtendedResourceCapacity() bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ManagerImpl) setPodPendingAdmission(pod *v1.Pod) {
|
||||||
|
m.mutex.Lock()
|
||||||
|
defer m.mutex.Unlock()
|
||||||
|
|
||||||
|
m.pendingAdmissionPod = pod
|
||||||
|
}
|
||||||
|
@ -29,6 +29,10 @@ import (
|
|||||||
// ensures the Device Manager is consulted when Topology Aware Hints for each
|
// ensures the Device Manager is consulted when Topology Aware Hints for each
|
||||||
// container are created.
|
// container are created.
|
||||||
func (m *ManagerImpl) GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint {
|
func (m *ManagerImpl) GetTopologyHints(pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint {
|
||||||
|
// The pod is during the admission phase. We need to save the pod to avoid it
|
||||||
|
// being cleaned before the admission ended
|
||||||
|
m.setPodPendingAdmission(pod)
|
||||||
|
|
||||||
// Garbage collect any stranded device resources before providing TopologyHints
|
// Garbage collect any stranded device resources before providing TopologyHints
|
||||||
m.UpdateAllocatedDevices()
|
m.UpdateAllocatedDevices()
|
||||||
|
|
||||||
@ -83,6 +87,10 @@ func (m *ManagerImpl) GetTopologyHints(pod *v1.Pod, container *v1.Container) map
|
|||||||
// GetPodTopologyHints implements the topologymanager.HintProvider Interface which
|
// GetPodTopologyHints implements the topologymanager.HintProvider Interface which
|
||||||
// ensures the Device Manager is consulted when Topology Aware Hints for Pod are created.
|
// ensures the Device Manager is consulted when Topology Aware Hints for Pod are created.
|
||||||
func (m *ManagerImpl) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint {
|
func (m *ManagerImpl) GetPodTopologyHints(pod *v1.Pod) map[string][]topologymanager.TopologyHint {
|
||||||
|
// The pod is during the admission phase. We need to save the pod to avoid it
|
||||||
|
// being cleaned before the admission ended
|
||||||
|
m.setPodPendingAdmission(pod)
|
||||||
|
|
||||||
// Garbage collect any stranded device resources before providing TopologyHints
|
// Garbage collect any stranded device resources before providing TopologyHints
|
||||||
m.UpdateAllocatedDevices()
|
m.UpdateAllocatedDevices()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user