diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 02f81725f03..a6e8fa9c880 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -128,7 +128,7 @@ type Runtime interface { // and store the resulting archive to the checkpoint directory. CheckpointContainer(ctx context.Context, options *runtimeapi.CheckpointContainerRequest) error // Generate pod status from the CRI event - GeneratePodStatus(event *runtimeapi.ContainerEventResponse) (*PodStatus, error) + GeneratePodStatus(event *runtimeapi.ContainerEventResponse) *PodStatus // ListMetricDescriptors gets the descriptors for the metrics that will be returned in ListPodSandboxMetrics. // This list should be static at startup: either the client and server restart together when // adding or removing metrics descriptors, or they should not change. diff --git a/pkg/kubelet/container/testing/fake_runtime.go b/pkg/kubelet/container/testing/fake_runtime.go index 226972a44a7..9d7ef2191d7 100644 --- a/pkg/kubelet/container/testing/fake_runtime.go +++ b/pkg/kubelet/container/testing/fake_runtime.go @@ -289,13 +289,13 @@ func (f *FakeRuntime) KillContainerInPod(container v1.Container, pod *v1.Pod) er return f.Err } -func (f *FakeRuntime) GeneratePodStatus(event *runtimeapi.ContainerEventResponse) (*kubecontainer.PodStatus, error) { +func (f *FakeRuntime) GeneratePodStatus(event *runtimeapi.ContainerEventResponse) *kubecontainer.PodStatus { f.Lock() defer f.Unlock() f.CalledFunctions = append(f.CalledFunctions, "GeneratePodStatus") status := f.PodStatus - return &status, f.Err + return &status } func (f *FakeRuntime) GetPodStatus(_ context.Context, uid types.UID, name, namespace string) (*kubecontainer.PodStatus, error) { diff --git a/pkg/kubelet/container/testing/runtime_mock.go b/pkg/kubelet/container/testing/runtime_mock.go index d53f2089b1a..d25229ce707 100644 --- a/pkg/kubelet/container/testing/runtime_mock.go +++ b/pkg/kubelet/container/testing/runtime_mock.go @@ -254,7 +254,7 @@ func (_c *MockRuntime_GarbageCollect_Call) RunAndReturn(run func(context.Context } // GeneratePodStatus provides a mock function with given fields: event -func (_m *MockRuntime) GeneratePodStatus(event *v1.ContainerEventResponse) (*container.PodStatus, error) { +func (_m *MockRuntime) GeneratePodStatus(event *v1.ContainerEventResponse) *container.PodStatus { ret := _m.Called(event) if len(ret) == 0 { @@ -262,10 +262,6 @@ func (_m *MockRuntime) GeneratePodStatus(event *v1.ContainerEventResponse) (*con } var r0 *container.PodStatus - var r1 error - if rf, ok := ret.Get(0).(func(*v1.ContainerEventResponse) (*container.PodStatus, error)); ok { - return rf(event) - } if rf, ok := ret.Get(0).(func(*v1.ContainerEventResponse) *container.PodStatus); ok { r0 = rf(event) } else { @@ -274,13 +270,7 @@ func (_m *MockRuntime) GeneratePodStatus(event *v1.ContainerEventResponse) (*con } } - if rf, ok := ret.Get(1).(func(*v1.ContainerEventResponse) error); ok { - r1 = rf(event) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } // MockRuntime_GeneratePodStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePodStatus' @@ -301,12 +291,12 @@ func (_c *MockRuntime_GeneratePodStatus_Call) Run(run func(event *v1.ContainerEv return _c } -func (_c *MockRuntime_GeneratePodStatus_Call) Return(_a0 *container.PodStatus, _a1 error) *MockRuntime_GeneratePodStatus_Call { - _c.Call.Return(_a0, _a1) +func (_c *MockRuntime_GeneratePodStatus_Call) Return(_a0 *container.PodStatus) *MockRuntime_GeneratePodStatus_Call { + _c.Call.Return(_a0) return _c } -func (_c *MockRuntime_GeneratePodStatus_Call) RunAndReturn(run func(*v1.ContainerEventResponse) (*container.PodStatus, error)) *MockRuntime_GeneratePodStatus_Call { +func (_c *MockRuntime_GeneratePodStatus_Call) RunAndReturn(run func(*v1.ContainerEventResponse) *container.PodStatus) *MockRuntime_GeneratePodStatus_Call { _c.Call.Return(run) return _c } diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index b48c022911d..6b049c67004 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -1590,7 +1590,7 @@ func (m *kubeGenericRuntimeManager) killPodWithSyncResult(ctx context.Context, p return } -func (m *kubeGenericRuntimeManager) GeneratePodStatus(event *runtimeapi.ContainerEventResponse) (*kubecontainer.PodStatus, error) { +func (m *kubeGenericRuntimeManager) GeneratePodStatus(event *runtimeapi.ContainerEventResponse) *kubecontainer.PodStatus { podIPs := m.determinePodSandboxIPs(event.PodSandboxStatus.Metadata.Namespace, event.PodSandboxStatus.Metadata.Name, event.PodSandboxStatus) kubeContainerStatuses := []*kubecontainer.Status{} @@ -1607,7 +1607,7 @@ func (m *kubeGenericRuntimeManager) GeneratePodStatus(event *runtimeapi.Containe IPs: podIPs, SandboxStatuses: []*runtimeapi.PodSandboxStatus{event.PodSandboxStatus}, ContainerStatuses: kubeContainerStatuses, - }, nil + } } // GetPodStatus retrieves the status of the pod, including the diff --git a/pkg/kubelet/pleg/evented.go b/pkg/kubelet/pleg/evented.go index 39e13b55223..c0a3ca5c987 100644 --- a/pkg/kubelet/pleg/evented.go +++ b/pkg/kubelet/pleg/evented.go @@ -231,28 +231,17 @@ func (e *EventedPLEG) processCRIEvents(containerEventsResponseCh chan *runtimeap podID := types.UID(event.PodSandboxStatus.Metadata.Uid) shouldSendPLEGEvent := false - status, err := e.runtime.GeneratePodStatus(event) - if err != nil { - // nolint:logcheck // Not using the result of klog.V inside the - // if branch is okay, we just use it to determine whether the - // additional "podStatus" key and its value should be added. - if klog.V(6).Enabled() { - e.logger.Error(err, "Evented PLEG: error generating pod status from the received event", "podUID", podID, "podStatus", status) - } else { - e.logger.Error(err, "Evented PLEG: error generating pod status from the received event", "podUID", podID) - } + status := e.runtime.GeneratePodStatus(event) + if klogV := e.logger.V(6); klogV.Enabled() { + e.logger.Info("Evented PLEG: Generated pod status from the received event", "podUID", podID, "podStatus", status) } else { - if klogV := e.logger.V(6); klogV.Enabled() { - e.logger.Info("Evented PLEG: Generated pod status from the received event", "podUID", podID, "podStatus", status) - } else { - e.logger.V(4).Info("Evented PLEG: Generated pod status from the received event", "podUID", podID) - } - // Preserve the pod IP across cache updates if the new IP is empty. - // When a pod is torn down, kubelet may race with PLEG and retrieve - // a pod status after network teardown, but the kubernetes API expects - // the completed pod's IP to be available after the pod is dead. - status.IPs = e.getPodIPs(podID, status) + e.logger.V(4).Info("Evented PLEG: Generated pod status from the received event", "podUID", podID) } + // Preserve the pod IP across cache updates if the new IP is empty. + // When a pod is torn down, kubelet may race with PLEG and retrieve + // a pod status after network teardown, but the kubernetes API expects + // the completed pod's IP to be available after the pod is dead. + status.IPs = e.getPodIPs(podID, status) e.updateRunningPodMetric(status) e.updateRunningContainerMetric(status) @@ -270,7 +259,7 @@ func (e *EventedPLEG) processCRIEvents(containerEventsResponseCh chan *runtimeap } shouldSendPLEGEvent = true } else { - if e.cache.Set(podID, status, err, time.Unix(0, event.GetCreatedAt())) { + if e.cache.Set(podID, status, nil, time.Unix(0, event.GetCreatedAt())) { shouldSendPLEGEvent = true } }