From eb0cab5b1837311e92c32e28ee0fa25b15068897 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Fri, 15 Sep 2017 16:26:15 -0400 Subject: [PATCH] Do not set message when terminationMessagePath not found If terminationMessagePath is set to a file that does not exist, we should not log an error message and instead try falling back to logs (based on the user's request). --- .../kuberuntime/kuberuntime_container.go | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index a673c8ceedb..a29f1215279 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -368,20 +368,22 @@ func makeUID() string { // getTerminationMessage looks on the filesystem for the provided termination message path, returning a limited // amount of those bytes, or returns true if the logs should be checked. func getTerminationMessage(status *runtimeapi.ContainerStatus, terminationMessagePath string, fallbackToLogs bool) (string, bool) { - if len(terminationMessagePath) != 0 { - for _, mount := range status.Mounts { - if mount.ContainerPath != terminationMessagePath { - continue - } - path := mount.HostPath - data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength) - if err != nil { - return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false - } - if !fallbackToLogs || len(data) != 0 { - return string(data), false - } + if len(terminationMessagePath) == 0 { + return "", fallbackToLogs + } + for _, mount := range status.Mounts { + if mount.ContainerPath != terminationMessagePath { + continue } + path := mount.HostPath + data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength) + if err != nil { + if os.IsNotExist(err) { + return "", fallbackToLogs + } + return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false + } + return string(data), (fallbackToLogs && len(data) == 0) } return "", fallbackToLogs }