Skip to content

Commit 5a0bc10

Browse files
committed
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 <[email protected]>
1 parent a89c843 commit 5a0bc10

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

pkg/kubelet/cm/cpumanager/cpu_manager.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,28 @@ func (m *manager) removeStaleState() {
380380
assignments := m.state.GetCPUAssignments()
381381
for podUID := range assignments {
382382
for containerName := range assignments[podUID] {
383-
if _, ok := activeContainers[podUID][containerName]; !ok {
384-
klog.V(2).InfoS("RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName)
385-
err := m.policyRemoveContainerByRef(podUID, containerName)
386-
if err != nil {
387-
klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName)
388-
}
383+
if _, ok := activeContainers[podUID][containerName]; ok {
384+
klog.V(4).InfoS("RemoveStaleState: container still active", "podUID", podUID, "containerName", containerName)
385+
continue
389386
}
390-
}
391-
}
392-
393-
m.containerMap.Visit(func(podUID, containerName, containerID string) {
394-
if _, ok := activeContainers[podUID][containerName]; !ok {
395387
klog.V(2).InfoS("RemoveStaleState: removing container", "podUID", podUID, "containerName", containerName)
396388
err := m.policyRemoveContainerByRef(podUID, containerName)
397389
if err != nil {
398390
klog.ErrorS(err, "RemoveStaleState: failed to remove container", "podUID", podUID, "containerName", containerName)
399391
}
400392
}
393+
}
394+
395+
m.containerMap.Visit(func(podUID, containerName, containerID string) {
396+
if _, ok := activeContainers[podUID][containerName]; ok {
397+
klog.V(4).InfoS("RemoveStaleState: containerMap: container still active", "podUID", podUID, "containerName", containerName)
398+
return
399+
}
400+
klog.V(2).InfoS("RemoveStaleState: containerMap: removing container", "podUID", podUID, "containerName", containerName)
401+
err := m.policyRemoveContainerByRef(podUID, containerName)
402+
if err != nil {
403+
klog.ErrorS(err, "RemoveStaleState: containerMap: failed to remove container", "podUID", podUID, "containerName", containerName)
404+
}
401405
})
402406
}
403407

0 commit comments

Comments
 (0)