mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
kubelet: use filepath.Clean before init, validate it in setupDataDirs
This commit is contained in:
parent
8b2dae57d4
commit
7afcfe1826
@ -20,6 +20,7 @@ package options
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
_ "net/http/pprof" // Enable pprof HTTP handlers.
|
_ "net/http/pprof" // Enable pprof HTTP handlers.
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -138,7 +139,7 @@ func NewKubeletFlags() *KubeletFlags {
|
|||||||
return &KubeletFlags{
|
return &KubeletFlags{
|
||||||
ContainerRuntimeOptions: *NewContainerRuntimeOptions(),
|
ContainerRuntimeOptions: *NewContainerRuntimeOptions(),
|
||||||
CertDirectory: "/var/lib/kubelet/pki",
|
CertDirectory: "/var/lib/kubelet/pki",
|
||||||
RootDirectory: defaultRootDir,
|
RootDirectory: filepath.Clean(defaultRootDir),
|
||||||
MaxContainerCount: -1,
|
MaxContainerCount: -1,
|
||||||
MaxPerPodContainerCount: 1,
|
MaxPerPodContainerCount: 1,
|
||||||
MinimumGCAge: metav1.Duration{Duration: 0},
|
MinimumGCAge: metav1.Duration{Duration: 0},
|
||||||
|
@ -523,7 +523,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
|
|||||||
kubeClient: kubeDeps.KubeClient,
|
kubeClient: kubeDeps.KubeClient,
|
||||||
heartbeatClient: kubeDeps.HeartbeatClient,
|
heartbeatClient: kubeDeps.HeartbeatClient,
|
||||||
onRepeatedHeartbeatFailure: kubeDeps.OnHeartbeatFailure,
|
onRepeatedHeartbeatFailure: kubeDeps.OnHeartbeatFailure,
|
||||||
rootDirectory: rootDirectory,
|
rootDirectory: filepath.Clean(rootDirectory),
|
||||||
resyncInterval: kubeCfg.SyncFrequency.Duration,
|
resyncInterval: kubeCfg.SyncFrequency.Duration,
|
||||||
sourcesReady: config.NewSourcesReady(kubeDeps.PodConfig.SeenAllSources),
|
sourcesReady: config.NewSourcesReady(kubeDeps.PodConfig.SeenAllSources),
|
||||||
registerNode: registerNode,
|
registerNode: registerNode,
|
||||||
@ -1321,7 +1321,9 @@ func (kl *Kubelet) RlimitStats() (*statsapi.RlimitStats, error) {
|
|||||||
// 4. the pod-resources directory
|
// 4. the pod-resources directory
|
||||||
// 5. the checkpoint directory
|
// 5. the checkpoint directory
|
||||||
func (kl *Kubelet) setupDataDirs() error {
|
func (kl *Kubelet) setupDataDirs() error {
|
||||||
kl.rootDirectory = filepath.Clean(kl.rootDirectory)
|
if cleanedRoot := filepath.Clean(kl.rootDirectory); cleanedRoot != kl.rootDirectory {
|
||||||
|
return fmt.Errorf("rootDirectory not in canonical form: expected %s, was %s", cleanedRoot, kl.rootDirectory)
|
||||||
|
}
|
||||||
pluginRegistrationDir := kl.getPluginsRegistrationDir()
|
pluginRegistrationDir := kl.getPluginsRegistrationDir()
|
||||||
pluginsDir := kl.getPluginsDir()
|
pluginsDir := kl.getPluginsDir()
|
||||||
if err := os.MkdirAll(kl.getRootDir(), 0750); err != nil {
|
if err := os.MkdirAll(kl.getRootDir(), 0750); err != nil {
|
||||||
|
@ -19,6 +19,7 @@ package kubelet
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ func TestRunOnce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(basePath)
|
defer os.RemoveAll(basePath)
|
||||||
kb := &Kubelet{
|
kb := &Kubelet{
|
||||||
rootDirectory: basePath,
|
rootDirectory: filepath.Clean(basePath),
|
||||||
recorder: &record.FakeRecorder{},
|
recorder: &record.FakeRecorder{},
|
||||||
cadvisor: cadvisor,
|
cadvisor: cadvisor,
|
||||||
nodeLister: testNodeLister{},
|
nodeLister: testNodeLister{},
|
||||||
|
Loading…
Reference in New Issue
Block a user