[cri] ensure log dir is created

containerd is responsible for creating the log but there is no code to ensure
that the log dir exists.  While kubelet should have created this there can be
times where this is not the case and this can cause stuck tasks.

Signed-off-by: Michael Crosby <michael@thepasture.io>
This commit is contained in:
Michael Crosby 2020-12-17 15:04:39 -05:00
parent 3cd1c832ef
commit 2e442ea485

View File

@ -156,6 +156,9 @@ func (c *criService) seccompEnabled() bool {
// openLogFile opens/creates a container log file. // openLogFile opens/creates a container log file.
func openLogFile(path string) (*os.File, error) { func openLogFile(path string) (*os.File, error) {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return nil, err
}
return os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640) return os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640)
} }