validate cadvisor rootpath

This commit is contained in:
Di Xu
2017-07-05 14:08:47 +08:00
parent 6fbc554c6b
commit 6c7245d464
2 changed files with 28 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"net"
"net/http"
"os"
"strconv"
"time"
@@ -105,6 +106,14 @@ func New(address string, port uint, runtime string, rootPath string) (Interface,
return nil, err
}
if _, err := os.Stat(rootPath); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("rootDirectory %q does not exist", rootPath)
} else {
return nil, fmt.Errorf("failed to Stat %q: %v", rootPath, err)
}
}
cadvisorClient := &cadvisorClient{
runtime: runtime,
rootPath: rootPath,