From f82be3d3d05f67d0d1301ee6bfab4fca0b1a47ac Mon Sep 17 00:00:00 2001 From: Yuqi Wang Date: Mon, 12 Aug 2019 16:15:59 +0800 Subject: [PATCH] Fix Container exit message lost due to FallbackToLogsOnError is not compatible with ContainerCannotRun --- pkg/kubelet/kuberuntime/kuberuntime_container.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 2983bbec76a..1064565b8c3 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -402,7 +402,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 @@ -415,9 +417,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