Update pluginwatcher to ignore CSI metadata dir and non socket files
This commit is contained in:
@@ -21,6 +21,7 @@ const (
|
|||||||
DefaultKubeletVolumesDirName = "volumes"
|
DefaultKubeletVolumesDirName = "volumes"
|
||||||
DefaultKubeletVolumeDevicesDirName = "volumeDevices"
|
DefaultKubeletVolumeDevicesDirName = "volumeDevices"
|
||||||
DefaultKubeletPluginsDirName = "plugins"
|
DefaultKubeletPluginsDirName = "plugins"
|
||||||
|
DefaultKubeletPluginsRegistrationDirName = "plugins_registry"
|
||||||
DefaultKubeletContainersDirName = "containers"
|
DefaultKubeletContainersDirName = "containers"
|
||||||
DefaultKubeletPluginContainersDirName = "plugin-containers"
|
DefaultKubeletPluginContainersDirName = "plugin-containers"
|
||||||
DefaultKubeletPodResourcesDirName = "pod-resources"
|
DefaultKubeletPodResourcesDirName = "pod-resources"
|
||||||
|
@@ -789,7 +789,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if klet.enablePluginsWatcher {
|
if klet.enablePluginsWatcher {
|
||||||
klet.pluginWatcher = pluginwatcher.NewWatcher(klet.getPluginsDir())
|
klet.pluginWatcher = pluginwatcher.NewWatcher(klet.getPluginsRegistrationDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the experimentalMounterPathFlag is set, we do not want to
|
// If the experimentalMounterPathFlag is set, we do not want to
|
||||||
@@ -1260,6 +1260,9 @@ func (kl *Kubelet) setupDataDirs() error {
|
|||||||
if err := os.MkdirAll(kl.getPluginsDir(), 0750); err != nil {
|
if err := os.MkdirAll(kl.getPluginsDir(), 0750); err != nil {
|
||||||
return fmt.Errorf("error creating plugins directory: %v", err)
|
return fmt.Errorf("error creating plugins directory: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := os.MkdirAll(kl.getPluginsRegistrationDir(), 0750); err != nil {
|
||||||
|
return fmt.Errorf("error creating plugins registry directory: %v", err)
|
||||||
|
}
|
||||||
if err := os.MkdirAll(kl.getPodResourcesDir(), 0750); err != nil {
|
if err := os.MkdirAll(kl.getPodResourcesDir(), 0750); err != nil {
|
||||||
return fmt.Errorf("error creating podresources directory: %v", err)
|
return fmt.Errorf("error creating podresources directory: %v", err)
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,14 @@ func (kl *Kubelet) getPluginsDir() string {
|
|||||||
return filepath.Join(kl.getRootDir(), config.DefaultKubeletPluginsDirName)
|
return filepath.Join(kl.getRootDir(), config.DefaultKubeletPluginsDirName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPluginsRegistrationDir returns the full path to the directory under which
|
||||||
|
// plugins socket should be placed to be registered.
|
||||||
|
// More information is available about plugin registration in the pluginwatcher
|
||||||
|
// module
|
||||||
|
func (kl *Kubelet) getPluginsRegistrationDir() string {
|
||||||
|
return filepath.Join(kl.getRootDir(), config.DefaultKubeletPluginsRegistrationDirName)
|
||||||
|
}
|
||||||
|
|
||||||
// getPluginDir returns a data directory name for a given plugin name.
|
// getPluginDir returns a data directory name for a given plugin name.
|
||||||
// Plugins can use these directories to store data that they need to persist.
|
// Plugins can use these directories to store data that they need to persist.
|
||||||
// For per-pod plugin data, see getPodPluginDir.
|
// For per-pod plugin data, see getPodPluginDir.
|
||||||
|
@@ -29,6 +29,7 @@ go_test(
|
|||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/kubelet/apis/pluginregistration/v1:go_default_library",
|
"//pkg/kubelet/apis/pluginregistration/v1:go_default_library",
|
||||||
|
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
],
|
],
|
||||||
|
@@ -211,6 +211,8 @@ func (w *Watcher) traversePluginDir(dir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle filesystem notify event.
|
// Handle filesystem notify event.
|
||||||
|
// Files names:
|
||||||
|
// - MUST NOT start with a '.'
|
||||||
func (w *Watcher) handleCreateEvent(event fsnotify.Event) error {
|
func (w *Watcher) handleCreateEvent(event fsnotify.Event) error {
|
||||||
klog.V(6).Infof("Handling create event: %v", event)
|
klog.V(6).Infof("Handling create event: %v", event)
|
||||||
|
|
||||||
@@ -220,11 +222,16 @@ func (w *Watcher) handleCreateEvent(event fsnotify.Event) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(fi.Name(), ".") {
|
if strings.HasPrefix(fi.Name(), ".") {
|
||||||
klog.Errorf("Ignoring file: %s", fi.Name())
|
klog.V(5).Infof("Ignoring file (starts with '.'): %s", fi.Name())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !fi.IsDir() {
|
if !fi.IsDir() {
|
||||||
|
if fi.Mode()&os.ModeSocket == 0 {
|
||||||
|
klog.V(5).Infof("Ignoring non socket file %s", fi.Name())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return w.handlePluginRegistration(event.Name)
|
return w.handlePluginRegistration(event.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +297,8 @@ func (w *Watcher) handleDeleteEvent(event fsnotify.Event) error {
|
|||||||
|
|
||||||
plugin, ok := w.getPlugin(event.Name)
|
plugin, ok := w.getPlugin(event.Name)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("could not find plugin for deleted file %s", event.Name)
|
klog.V(5).Infof("could not find plugin for deleted file %s", event.Name)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// You should not get a Deregister call while registering a plugin
|
// You should not get a Deregister call while registering a plugin
|
||||||
|
Reference in New Issue
Block a user