From 5f8dd349d1db2860c7e8174fa1c20f6b2e2a56bc Mon Sep 17 00:00:00 2001 From: Jiaming Xu Date: Sat, 6 Mar 2021 00:49:41 +0000 Subject: [PATCH] Add exit code log when container died update log exit code logic adjust log exit code logic fix invalid memory access in unit test adjust log update log message address latest comment change logging format remove space in key of log address latest comments address comments --- pkg/kubelet/pleg/generic.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/kubelet/pleg/generic.go b/pkg/kubelet/pleg/generic.go index 137569633a6..69e7e080604 100644 --- a/pkg/kubelet/pleg/generic.go +++ b/pkg/kubelet/pleg/generic.go @@ -264,6 +264,10 @@ func (g *GenericPLEG) relist() { } // Update the internal storage and send out the events. g.podRecords.update(pid) + + // Map from containerId to exit code; used as a temporary cache for lookup + containerExitCode := make(map[string]int) + for i := range events { // Filter out events that are not reliable and no other components use yet. if events[i].Type == ContainerChanged { @@ -275,6 +279,24 @@ func (g *GenericPLEG) relist() { metrics.PLEGDiscardEvents.Inc() klog.ErrorS(nil, "Event channel is full, discard this relist() cycle event") } + // Log exit code of containers when they finished in a particular event + if events[i].Type == ContainerDied { + // Fill up containerExitCode map for ContainerDied event when first time appeared + if len(containerExitCode) == 0 && pod != nil && g.cache != nil { + // Get updated podStatus + status, err := g.cache.Get(pod.ID) + if err == nil { + for _, containerStatus := range status.ContainerStatuses { + containerExitCode[containerStatus.ID.ID] = containerStatus.ExitCode + } + } + } + if containerID, ok := events[i].Data.(string); ok { + if exitCode, ok := containerExitCode[containerID]; ok { + klog.V(2).InfoS("Generic (PLEG): container finished", "podID", pod.ID, "containerID", containerID, "exitCode", exitCode) + } + } + } } }