From f6cf9b8ce930ddeb295281dace3df494c2522d7c Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Thu, 24 Oct 2019 16:23:58 +0200 Subject: [PATCH] Move CPUManager Pod Status logic before container loop --- pkg/kubelet/cm/cpumanager/cpu_manager.go | 20 +++++++++---------- pkg/kubelet/cm/cpumanager/cpu_manager_test.go | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager.go b/pkg/kubelet/cm/cpumanager/cpu_manager.go index ec9ae4333be..885ed90195a 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager.go @@ -350,19 +350,19 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec m.removeStaleState() for _, pod := range m.activePods() { + pstatus, ok := m.podStatusProvider.GetPodStatus(pod.UID) + if !ok { + klog.Warningf("[cpumanager] reconcileState: skipping pod; status not found (pod: %s)", pod.Name) + failure = append(failure, reconciledContainer{pod.Name, "", ""}) + continue + } + allContainers := pod.Spec.InitContainers allContainers = append(allContainers, pod.Spec.Containers...) - status, ok := m.podStatusProvider.GetPodStatus(pod.UID) for _, container := range allContainers { - if !ok { - klog.Warningf("[cpumanager] reconcileState: skipping pod; status not found (pod: %s)", pod.Name) - failure = append(failure, reconciledContainer{pod.Name, container.Name, ""}) - break - } - - containerID, err := findContainerIDByName(&status, container.Name) + containerID, err := findContainerIDByName(&pstatus, container.Name) if err != nil { - klog.Warningf("[cpumanager] reconcileState: skipping container; ID not found in status (pod: %s, container: %s, error: %v)", pod.Name, container.Name, err) + klog.Warningf("[cpumanager] reconcileState: skipping container; ID not found in pod status (pod: %s, container: %s, error: %v)", pod.Name, container.Name, err) failure = append(failure, reconciledContainer{pod.Name, container.Name, ""}) continue } @@ -372,7 +372,7 @@ func (m *manager) reconcileState() (success []reconciledContainer, failure []rec // - kubelet has just been restarted - and there is no previous state file // - container has been removed from state by RemoveContainer call (DeletionTimestamp is set) if _, ok := m.state.GetCPUSet(string(pod.UID), container.Name); !ok { - if status.Phase == v1.PodRunning && pod.DeletionTimestamp == nil { + if pstatus.Phase == v1.PodRunning && pod.DeletionTimestamp == nil { 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) err := m.AddContainer(pod, &container, containerID) if err != nil { diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go index c1c494583dc..6800060308a 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go @@ -774,7 +774,7 @@ func TestReconcileState(t *testing.T) { stDefaultCPUSet: cpuset.NewCPUSet(), updateErr: nil, expectSucceededContainerName: "", - expectFailedContainerName: "fakeContainerName", + expectFailedContainerName: "", }, { description: "cpu manager reconclie - container id not found",