Merge pull request #52503 from joelsmith/journald-log-fallback
Automatic merge from submit-queue (batch tested with PRs 54040, 52503). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Get fallback termination msg from docker when using journald log driver **What this PR does / why we need it**: When using the legacy docker container runtime and when a container has `terminationMessagePolicy=FallbackToLogsOnError` and when docker is configured with a log driver other than `json-log` (such as `journald`), the kubelet should not try to get the container's log from the json log file (since it's not there) but should instead ask docker for the logs. **Which issue this PR fixes** fixes #52502 **Special notes for your reviewer**: **Release note**: ```release-note Fixed log fallback termination messages when using docker with journald log driver ```
This commit is contained in:
@@ -427,8 +427,16 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n
|
||||
fallbackToLogs := annotatedInfo.TerminationMessagePolicy == v1.TerminationMessageFallbackToLogsOnError && cStatus.ExitCode != 0
|
||||
tMessage, checkLogs := getTerminationMessage(status, annotatedInfo.TerminationMessagePath, fallbackToLogs)
|
||||
if checkLogs {
|
||||
path := buildFullContainerLogsPath(uid, labeledInfo.ContainerName, annotatedInfo.RestartCount)
|
||||
tMessage = m.readLastStringFromContainerLogs(path)
|
||||
// if dockerLegacyService is populated, we're supposed to use it to fetch logs
|
||||
if m.legacyLogProvider != nil {
|
||||
tMessage, err = m.legacyLogProvider.GetContainerLogTail(uid, name, namespace, kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id})
|
||||
if err != nil {
|
||||
tMessage = fmt.Sprintf("Error reading termination message from logs: %v", err)
|
||||
}
|
||||
} else {
|
||||
path := buildFullContainerLogsPath(uid, labeledInfo.ContainerName, annotatedInfo.RestartCount)
|
||||
tMessage = m.readLastStringFromContainerLogs(path)
|
||||
}
|
||||
}
|
||||
// Use the termination message written by the application is not empty
|
||||
if len(tMessage) != 0 {
|
||||
|
Reference in New Issue
Block a user