mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
validate cadvisor rootpath
This commit is contained in:
parent
6fbc554c6b
commit
6c7245d464
@ -23,6 +23,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -105,6 +106,14 @@ func New(address string, port uint, runtime string, rootPath string) (Interface,
|
|||||||
return nil, err
|
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{
|
cadvisorClient := &cadvisorClient{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
rootPath: rootPath,
|
rootPath: rootPath,
|
||||||
|
@ -83,6 +83,7 @@ const (
|
|||||||
// Ports of different e2e services.
|
// Ports of different e2e services.
|
||||||
kubeletPort = "10250"
|
kubeletPort = "10250"
|
||||||
kubeletReadOnlyPort = "10255"
|
kubeletReadOnlyPort = "10255"
|
||||||
|
kubeletRootDirectory = "/var/lib/kubelet"
|
||||||
// Health check url of kubelet
|
// Health check url of kubelet
|
||||||
kubeletHealthCheckURL = "http://127.0.0.1:" + kubeletReadOnlyPort + "/healthz"
|
kubeletHealthCheckURL = "http://127.0.0.1:" + kubeletReadOnlyPort + "/healthz"
|
||||||
)
|
)
|
||||||
@ -104,6 +105,10 @@ func (e *E2EServices) startKubelet() (*server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
e.rmDirs = append(e.rmDirs, manifestPath)
|
e.rmDirs = append(e.rmDirs, manifestPath)
|
||||||
|
err = createRootDirectory(kubeletRootDirectory)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
var killCommand, restartCommand *exec.Cmd
|
var killCommand, restartCommand *exec.Cmd
|
||||||
var isSystemd bool
|
var isSystemd bool
|
||||||
// Apply default kubelet flags.
|
// Apply default kubelet flags.
|
||||||
@ -139,6 +144,7 @@ func (e *E2EServices) startKubelet() (*server, error) {
|
|||||||
"--address", "0.0.0.0",
|
"--address", "0.0.0.0",
|
||||||
"--port", kubeletPort,
|
"--port", kubeletPort,
|
||||||
"--read-only-port", kubeletReadOnlyPort,
|
"--read-only-port", kubeletReadOnlyPort,
|
||||||
|
"--root-dir", kubeletRootDirectory,
|
||||||
"--volume-stats-agg-period", "10s", // Aggregate volumes frequently so tests don't need to wait as long
|
"--volume-stats-agg-period", "10s", // Aggregate volumes frequently so tests don't need to wait as long
|
||||||
"--allow-privileged", "true",
|
"--allow-privileged", "true",
|
||||||
"--serialize-image-pulls", "false",
|
"--serialize-image-pulls", "false",
|
||||||
@ -237,6 +243,17 @@ current-context: local-context`)
|
|||||||
return nil
|
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) {
|
func kubeconfigCWDPath() (string, error) {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user