mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 22:05:59 +00:00
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:
parent
98ed5dd8a2
commit
eb0cab5b18
@ -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 {
|
|
||||||
return fmt.Sprintf("Error on reading termination log %s: %v", path, err), false
|
|
||||||
}
|
|
||||||
if !fallbackToLogs || len(data) != 0 {
|
|
||||||
return string(data), false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
return "", fallbackToLogs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user