Create the directory for cadvisor if needed

In 6c7245d464, code was added to
bail out if the directory that cadvisor monitored did not exist.

However, this breaks the earlier assumption that kubelet created
directories when needed in pkg/kubelet/kubelet.go's setupDataDirs()
method. setupDataDirs() happens much later, so basically kubelet
exits now.

So since cadvisor really needs this directory, let us just create
it

Fixes #50709
pull/6/head
Davanum Srinivas 2017-08-15 16:40:21 -04:00
parent 4d409a4d9e
commit ca2d5178aa
1 changed files with 4 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import (
"net"
"net/http"
"os"
"path"
"strconv"
"time"
@ -108,7 +109,9 @@ func New(address string, port uint, runtime string, rootPath string) (Interface,
if _, err := os.Stat(rootPath); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("rootDirectory %q does not exist", rootPath)
if err := os.MkdirAll(path.Clean(rootPath), 0750); err != nil {
return nil, fmt.Errorf("error creating root directory %q: %v", rootPath, err)
}
} else {
return nil, fmt.Errorf("failed to Stat %q: %v", rootPath, err)
}