diff --git a/pkg/kubelet/config/defaults.go b/pkg/kubelet/config/defaults.go index 16bd6cb564..96ab9cebac 100644 --- a/pkg/kubelet/config/defaults.go +++ b/pkg/kubelet/config/defaults.go @@ -17,11 +17,12 @@ limitations under the License. package config const ( - DefaultKubeletPodsDirName = "pods" - DefaultKubeletVolumesDirName = "volumes" - DefaultKubeletVolumeDevicesDirName = "volumeDevices" - DefaultKubeletPluginsDirName = "plugins" - DefaultKubeletContainersDirName = "containers" - DefaultKubeletPluginContainersDirName = "plugin-containers" - DefaultKubeletPodResourcesDirName = "pod-resources" + DefaultKubeletPodsDirName = "pods" + DefaultKubeletVolumesDirName = "volumes" + DefaultKubeletVolumeDevicesDirName = "volumeDevices" + DefaultKubeletPluginsDirName = "plugins" + DefaultKubeletPluginsRegistrationDirName = "plugins_registry" + DefaultKubeletContainersDirName = "containers" + DefaultKubeletPluginContainersDirName = "plugin-containers" + DefaultKubeletPodResourcesDirName = "pod-resources" ) diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 0e065a1b62..c44bbb0ede 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -789,7 +789,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, return nil, err } 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 @@ -1260,6 +1260,9 @@ func (kl *Kubelet) setupDataDirs() error { if err := os.MkdirAll(kl.getPluginsDir(), 0750); err != nil { 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 { return fmt.Errorf("error creating podresources directory: %v", err) } diff --git a/pkg/kubelet/kubelet_getters.go b/pkg/kubelet/kubelet_getters.go index 3e6bc43e9b..eb05a578c0 100644 --- a/pkg/kubelet/kubelet_getters.go +++ b/pkg/kubelet/kubelet_getters.go @@ -57,6 +57,14 @@ func (kl *Kubelet) getPluginsDir() string { 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. // Plugins can use these directories to store data that they need to persist. // For per-pod plugin data, see getPodPluginDir. diff --git a/pkg/kubelet/util/pluginwatcher/plugin_watcher.go b/pkg/kubelet/util/pluginwatcher/plugin_watcher.go index 03970f3cc0..06076c6ffa 100644 --- a/pkg/kubelet/util/pluginwatcher/plugin_watcher.go +++ b/pkg/kubelet/util/pluginwatcher/plugin_watcher.go @@ -211,6 +211,8 @@ func (w *Watcher) traversePluginDir(dir string) error { } // Handle filesystem notify event. +// Files names: +// - MUST NOT start with a '.' func (w *Watcher) handleCreateEvent(event fsnotify.Event) error { 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(), ".") { - klog.Errorf("Ignoring file: %s", fi.Name()) + klog.V(5).Infof("Ignoring file (starts with '.'): %s", fi.Name()) return nil } 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) } @@ -290,7 +297,8 @@ func (w *Watcher) handleDeleteEvent(event fsnotify.Event) error { plugin, ok := w.getPlugin(event.Name) 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 diff --git a/test/e2e/testing-manifests/storage-csi/gce-pd/node_ds.yaml b/test/e2e/testing-manifests/storage-csi/gce-pd/node_ds.yaml index 5f2f1ddd33..0ed8af1499 100644 --- a/test/e2e/testing-manifests/storage-csi/gce-pd/node_ds.yaml +++ b/test/e2e/testing-manifests/storage-csi/gce-pd/node_ds.yaml @@ -60,7 +60,7 @@ spec: volumes: - name: registration-dir hostPath: - path: /var/lib/kubelet/plugins/ + path: /var/lib/kubelet/plugins_registry/ type: Directory - name: kubelet-dir hostPath: diff --git a/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpathplugin.yaml b/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpathplugin.yaml index 4df7cea194..2c66e11eca 100644 --- a/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpathplugin.yaml +++ b/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpathplugin.yaml @@ -65,6 +65,6 @@ spec: type: DirectoryOrCreate name: mountpoint-dir - hostPath: - path: /var/lib/kubelet/plugins + path: /var/lib/kubelet/plugins_registry type: Directory name: registration-dir diff --git a/test/e2e_node/device_plugin.go b/test/e2e_node/device_plugin.go index 3951f8c538..3adde19871 100644 --- a/test/e2e_node/device_plugin.go +++ b/test/e2e_node/device_plugin.go @@ -53,7 +53,7 @@ var _ = framework.KubeDescribe("Device Plugin [Feature:DevicePlugin][NodeFeature var _ = framework.KubeDescribe("Device Plugin [Feature:DevicePluginProbe][NodeFeature:DevicePluginProbe][Serial]", func() { f := framework.NewDefaultFramework("device-plugin-errors") - testDevicePlugin(f, true, "/var/lib/kubelet/plugins/") + testDevicePlugin(f, true, "/var/lib/kubelet/plugins_registry") }) func testDevicePlugin(f *framework.Framework, enablePluginWatcher bool, pluginSockDir string) {