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
This commit is contained in:
Jiaming Xu 2021-03-06 00:49:41 +00:00
parent 3cde6b1999
commit 5f8dd349d1

View File

@ -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)
}
}
}
}
}