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).
This commit is contained in:
Clayton Coleman 2017-09-15 16:26:15 -04:00
parent 98ed5dd8a2
commit eb0cab5b18
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3

View File

@ -368,7 +368,9 @@ func makeUID() string {
// getTerminationMessage looks on the filesystem for the provided termination message path, returning a limited // 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. // amount of those bytes, or returns true if the logs should be checked.
func getTerminationMessage(status *runtimeapi.ContainerStatus, terminationMessagePath string, fallbackToLogs bool) (string, bool) { func getTerminationMessage(status *runtimeapi.ContainerStatus, terminationMessagePath string, fallbackToLogs bool) (string, bool) {
if len(terminationMessagePath) != 0 { if len(terminationMessagePath) == 0 {
return "", fallbackToLogs
}
for _, mount := range status.Mounts { for _, mount := range status.Mounts {
if mount.ContainerPath != terminationMessagePath { if mount.ContainerPath != terminationMessagePath {
continue continue
@ -376,12 +378,12 @@ func getTerminationMessage(status *runtimeapi.ContainerStatus, terminationMessag
path := mount.HostPath path := mount.HostPath
data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength) data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength)
if err != nil { if err != nil {
if os.IsNotExist(err) {
return "", fallbackToLogs
}
return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false
} }
if !fallbackToLogs || len(data) != 0 { return string(data), (fallbackToLogs && len(data) == 0)
return string(data), false
}
}
} }
return "", fallbackToLogs return "", fallbackToLogs
} }