Skip to content

Commit

Permalink
UPSTREAM: 109103: cpu manager policy set to none, no one remove conta…
Browse files Browse the repository at this point in the history
…iner id from container map, lead memory leak
  • Loading branch information
Dingshujie authored and openshift-cherrypick-robot committed Jul 12, 2022
1 parent 8cfebb1 commit bff0329
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/kubelet/cm/containermap/container_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ func (cm ContainerMap) GetContainerRef(containerID string) (string, string, erro
}
return cm[containerID].podUID, cm[containerID].containerName, nil
}

// Visit invoke visitor function to walks all of the entries in the container map
func (cm ContainerMap) Visit(visitor func(podUID, containerName, containerID string)) {
for k, v := range cm {
visitor(v.podUID, v.containerName, k)
}
}
10 changes: 10 additions & 0 deletions pkg/kubelet/cm/cpumanager/cpu_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ func (m *manager) removeStaleState() {
}
}
}

m.containerMap.Visit(func(podUID, containerName, containerID string) {
if _, ok := activeContainers[podUID][containerName]; !ok {
klog.ErrorS(nil, "RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName)
err := m.policyRemoveContainerByRef(podUID, containerName)
if err != nil {
klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName)
}
}
})
}

func (m *manager) reconcileState() (success []reconciledContainer, failure []reconciledContainer) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/kubelet/cm/memorymanager/memory_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ func (m *manager) removeStaleState() {
}
}
}

m.containerMap.Visit(func(podUID, containerName, containerID string) {
if _, ok := activeContainers[podUID][containerName]; !ok {
klog.InfoS("RemoveStaleState removing state", "podUID", podUID, "containerName", containerName)
m.policyRemoveContainerByRef(podUID, containerName)
}
})
}

func (m *manager) policyRemoveContainerByRef(podUID string, containerName string) {
Expand Down

0 comments on commit bff0329

Please sign in to comment.