mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Merge pull request #116833 from mpatlasov/fix-memleak-in-kubelet-volumemanager
Fix memory leak in kubelet volume_manager populator processedPods
This commit is contained in:
commit
f46626364f
@ -207,7 +207,9 @@ func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods() {
|
|||||||
// Iterate through all pods in desired state of world, and remove if they no
|
// Iterate through all pods in desired state of world, and remove if they no
|
||||||
// longer exist
|
// longer exist
|
||||||
func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() {
|
func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() {
|
||||||
|
podsFromCache := make(map[volumetypes.UniquePodName]struct{})
|
||||||
for _, volumeToMount := range dswp.desiredStateOfWorld.GetVolumesToMount() {
|
for _, volumeToMount := range dswp.desiredStateOfWorld.GetVolumesToMount() {
|
||||||
|
podsFromCache[volumetypes.UniquePodName(volumeToMount.Pod.UID)] = struct{}{}
|
||||||
pod, podExists := dswp.podManager.GetPodByUID(volumeToMount.Pod.UID)
|
pod, podExists := dswp.podManager.GetPodByUID(volumeToMount.Pod.UID)
|
||||||
if podExists {
|
if podExists {
|
||||||
|
|
||||||
@ -256,6 +258,23 @@ func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() {
|
|||||||
dswp.deleteProcessedPod(volumeToMount.PodName)
|
dswp.deleteProcessedPod(volumeToMount.PodName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup orphanded entries from processedPods
|
||||||
|
dswp.pods.Lock()
|
||||||
|
orphanedPods := make([]volumetypes.UniquePodName, 0, len(dswp.pods.processedPods))
|
||||||
|
for k := range dswp.pods.processedPods {
|
||||||
|
if _, ok := podsFromCache[k]; !ok {
|
||||||
|
orphanedPods = append(orphanedPods, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dswp.pods.Unlock()
|
||||||
|
for _, orphanedPod := range orphanedPods {
|
||||||
|
uid := types.UID(orphanedPod)
|
||||||
|
_, podExists := dswp.podManager.GetPodByUID(uid)
|
||||||
|
if !podExists && dswp.podStateProvider.ShouldPodRuntimeBeRemoved(uid) {
|
||||||
|
dswp.deleteProcessedPod(orphanedPod)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
podsWithError := dswp.desiredStateOfWorld.GetPodsWithErrors()
|
podsWithError := dswp.desiredStateOfWorld.GetPodsWithErrors()
|
||||||
for _, podName := range podsWithError {
|
for _, podName := range podsWithError {
|
||||||
if _, podExists := dswp.podManager.GetPodByUID(types.UID(podName)); !podExists {
|
if _, podExists := dswp.podManager.GetPodByUID(types.UID(podName)); !podExists {
|
||||||
|
@ -350,6 +350,15 @@ func TestFindAndAddNewPods_FindAndRemoveDeletedPods(t *testing.T) {
|
|||||||
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
t.Fatalf("Failed to remove pods from desired state of world since they no longer exist")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// podWorker may call volume_manager WaitForUnmount() after we processed the pod in findAndRemoveDeletedPods()
|
||||||
|
dswp.ReprocessPod(podName)
|
||||||
|
dswp.findAndRemoveDeletedPods()
|
||||||
|
|
||||||
|
// findAndRemoveDeletedPods() above must detect orphaned pod and delete it from the map
|
||||||
|
if _, ok := dswp.pods.processedPods[podName]; ok {
|
||||||
|
t.Fatalf("Failed to remove orphanded pods from internal map")
|
||||||
|
}
|
||||||
|
|
||||||
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
volumeExists := dswp.desiredStateOfWorld.VolumeExists(expectedVolumeName, "" /* SELinuxContext */)
|
||||||
if volumeExists {
|
if volumeExists {
|
||||||
t.Fatalf(
|
t.Fatalf(
|
||||||
|
Loading…
Reference in New Issue
Block a user