Merge pull request #81280 from yqwang-ms/yqwang/exitmsglost

Fix Container exit message lost due to FallbackToLogsOnError is not compatible with ContainerCannotRun
This commit is contained in:
Kubernetes Prow Robot 2019-10-08 15:41:51 -07:00 committed by GitHub
commit 4cff1c3ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -407,7 +407,9 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n
if status.State == runtimeapi.ContainerState_CONTAINER_EXITED {
// Populate the termination message if needed.
annotatedInfo := getContainerInfoFromAnnotations(status.Annotations)
fallbackToLogs := annotatedInfo.TerminationMessagePolicy == v1.TerminationMessageFallbackToLogsOnError && cStatus.ExitCode != 0
// If a container cannot even be started, it certainly does not have logs, so no need to fallbackToLogs.
fallbackToLogs := annotatedInfo.TerminationMessagePolicy == v1.TerminationMessageFallbackToLogsOnError &&
cStatus.ExitCode != 0 && cStatus.Reason != "ContainerCannotRun"
tMessage, checkLogs := getTerminationMessage(status, annotatedInfo.TerminationMessagePath, fallbackToLogs)
if checkLogs {
// if dockerLegacyService is populated, we're supposed to use it to fetch logs
@ -420,9 +422,12 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n
tMessage = m.readLastStringFromContainerLogs(status.GetLogPath())
}
}
// Use the termination message written by the application is not empty
// Enrich the termination message written by the application is not empty
if len(tMessage) != 0 {
cStatus.Message = tMessage
if len(cStatus.Message) != 0 {
cStatus.Message += ": "
}
cStatus.Message += tMessage
}
}
statuses[i] = cStatus