validate cadvisor rootpath
This commit is contained in:
parent
6fbc554c6b
commit
6c7245d464
@ -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,
|
||||
|
@ -81,8 +81,9 @@ func RunKubelet() {
|
||||
|
||||
const (
|
||||
// Ports of different e2e services.
|
||||
kubeletPort = "10250"
|
||||
kubeletReadOnlyPort = "10255"
|
||||
kubeletPort = "10250"
|
||||
kubeletReadOnlyPort = "10255"
|
||||
kubeletRootDirectory = "/var/lib/kubelet"
|
||||
// Health check url of kubelet
|
||||
kubeletHealthCheckURL = "http://127.0.0.1:" + kubeletReadOnlyPort + "/healthz"
|
||||
)
|
||||
@ -104,6 +105,10 @@ func (e *E2EServices) startKubelet() (*server, error) {
|
||||
return nil, err
|
||||
}
|
||||
e.rmDirs = append(e.rmDirs, manifestPath)
|
||||
err = createRootDirectory(kubeletRootDirectory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var killCommand, restartCommand *exec.Cmd
|
||||
var isSystemd bool
|
||||
// Apply default kubelet flags.
|
||||
@ -139,6 +144,7 @@ func (e *E2EServices) startKubelet() (*server, error) {
|
||||
"--address", "0.0.0.0",
|
||||
"--port", kubeletPort,
|
||||
"--read-only-port", kubeletReadOnlyPort,
|
||||
"--root-dir", kubeletRootDirectory,
|
||||
"--volume-stats-agg-period", "10s", // Aggregate volumes frequently so tests don't need to wait as long
|
||||
"--allow-privileged", "true",
|
||||
"--serialize-image-pulls", "false",
|
||||
@ -237,6 +243,17 @@ current-context: local-context`)
|
||||
return nil
|
||||
}
|
||||
|
||||
func createRootDirectory(path string) error {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return os.MkdirAll(path, os.FileMode(0755))
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func kubeconfigCWDPath() (string, error) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user