node: cpumgr: move flow to left and add logs

Refactor the code to align to the left bailing out
earlier if the code must do nothing.
Add log to trace this occurrence.
Besides extra log, no intended change in behavior.

Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
Francesco Romani
2023-09-11 15:10:51 +02:00
parent a89c843edd
commit 5a0bc1020b

View File

@@ -380,24 +380,28 @@ func (m *manager) removeStaleState() {
assignments := m.state.GetCPUAssignments() assignments := m.state.GetCPUAssignments()
for podUID := range assignments { for podUID := range assignments {
for containerName := range assignments[podUID] { for containerName := range assignments[podUID] {
if _, ok := activeContainers[podUID][containerName]; !ok { if _, ok := activeContainers[podUID][containerName]; ok {
klog.V(2).InfoS("RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName) klog.V(4).InfoS("RemoveStaleState: container still active", "podUID", podUID, "containerName", containerName)
err := m.policyRemoveContainerByRef(podUID, containerName) continue
if err != nil {
klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName)
}
} }
}
}
m.containerMap.Visit(func(podUID, containerName, containerID string) {
if _, ok := activeContainers[podUID][containerName]; !ok {
klog.V(2).InfoS("RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName) klog.V(2).InfoS("RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName)
err := m.policyRemoveContainerByRef(podUID, containerName) err := m.policyRemoveContainerByRef(podUID, containerName)
if err != nil { if err != nil {
klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName) klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName)
} }
} }
}
m.containerMap.Visit(func(podUID, containerName, containerID string) {
if _, ok := activeContainers[podUID][containerName]; ok {
klog.V(4).InfoS("RemoveStaleState: containerMap: container still active", "podUID", podUID, "containerName", containerName)
return
}
klog.V(2).InfoS("RemoveStaleState: containerMap: removing container", "podUID", podUID, "containerName", containerName)
err := m.policyRemoveContainerByRef(podUID, containerName)
if err != nil {
klog.ErrorS(err, "RemoveStaleState: containerMap: failed to remove container", "podUID", podUID, "containerName", containerName)
}
}) })
} }