Skip to content

Commit f6cf9b8

Browse files
committed
Move CPUManager Pod Status logic before container loop
1 parent f680c26 commit f6cf9b8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/kubelet/cm/cpumanager/cpu_manager.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,19 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec
350350

351351
m.removeStaleState()
352352
for _, pod := range m.activePods() {
353+
pstatus, ok := m.podStatusProvider.GetPodStatus(pod.UID)
354+
if !ok {
355+
klog.Warningf("[cpumanager] reconcileState: skipping pod; status not found (pod: %s)", pod.Name)
356+
failure = append(failure, reconciledContainer{pod.Name, "", ""})
357+
continue
358+
}
359+
353360
allContainers := pod.Spec.InitContainers
354361
allContainers = append(allContainers, pod.Spec.Containers...)
355-
status, ok := m.podStatusProvider.GetPodStatus(pod.UID)
356362
for _, container := range allContainers {
357-
if !ok {
358-
klog.Warningf("[cpumanager] reconcileState: skipping pod; status not found (pod: %s)", pod.Name)
359-
failure = append(failure, reconciledContainer{pod.Name, container.Name, ""})
360-
break
361-
}
362-
363-
containerID, err := findContainerIDByName(&status, container.Name)
363+
containerID, err := findContainerIDByName(&pstatus, container.Name)
364364
if err != nil {
365-
klog.Warningf("[cpumanager] reconcileState: skipping container; ID not found in status (pod: %s, container: %s, error: %v)", pod.Name, container.Name, err)
365+
klog.Warningf("[cpumanager] reconcileState: skipping container; ID not found in pod status (pod: %s, container: %s, error: %v)", pod.Name, container.Name, err)
366366
failure = append(failure, reconciledContainer{pod.Name, container.Name, ""})
367367
continue
368368
}
@@ -372,7 +372,7 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec
372372
// - kubelet has just been restarted - and there is no previous state file
373373
// - container has been removed from state by RemoveContainer call (DeletionTimestamp is set)
374374
if _, ok := m.state.GetCPUSet(string(pod.UID), container.Name); !ok {
375-
if status.Phase == v1.PodRunning && pod.DeletionTimestamp == nil {
375+
if pstatus.Phase == v1.PodRunning && pod.DeletionTimestamp == nil {
376376
klog.V(4).Infof("[cpumanager] reconcileState: container is not present in state - trying to add (pod: %s, container: %s, container id: %s)", pod.Name, container.Name, containerID)
377377
err := m.AddContainer(pod, &container, containerID)
378378
if err != nil {

pkg/kubelet/cm/cpumanager/cpu_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ func TestReconcileState(t *testing.T) {
774774
stDefaultCPUSet: cpuset.NewCPUSet(),
775775
updateErr: nil,
776776
expectSucceededContainerName: "",
777-
expectFailedContainerName: "fakeContainerName",
777+
expectFailedContainerName: "",
778778
},
779779
{
780780
description: "cpu manager reconclie - container id not found",

0 commit comments

Comments
 (0)