Commit cece3990 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #52567 from smarterclayton/fix_fallback_to_logs

Automatic merge from submit-queue (batch tested with PRs 50890, 52484, 52542, 52567, 50672). 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>.. 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 also slightly simplifies the terminationMessagePath processing. Seen in #50499 ```release-note If a container does not create a file at the `terminationMessagePath`, no message should be output about being unable to find the file. ```
parents 30bb5153 eb0cab5b
...@@ -368,20 +368,22 @@ func makeUID() string { ...@@ -368,20 +368,22 @@ 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 {
for _, mount := range status.Mounts { return "", fallbackToLogs
if mount.ContainerPath != terminationMessagePath { }
continue for _, mount := range status.Mounts {
} if mount.ContainerPath != terminationMessagePath {
path := mount.HostPath continue
data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength) }
if err != nil { path := mount.HostPath
return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false data, _, err := tail.ReadAtMost(path, kubecontainer.MaxContainerTerminationMessageLength)
} if err != nil {
if !fallbackToLogs || len(data) != 0 { if os.IsNotExist(err) {
return string(data), false return "", fallbackToLogs
} }
return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false
} }
return string(data), (fallbackToLogs && len(data) == 0)
} }
return "", fallbackToLogs return "", fallbackToLogs
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment