k3s/pkg/kubelet/util/pluginwatcher
hui luo d04f596829 Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,

- plugin socket directory
-    |
-    ---->sub directory 1
-    |              |
-    |              ----->  socket1,  socket2 ...
-    ----->sub directory 2
-                  |
-                  ------> socket1, socket2 ...

the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.

four bonus changes added as below

1. extract example handler out from test, it is easier to read the code
with the seperation.

2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.

3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures

4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-06-25 17:32:18 -07:00
..
example_plugin_apis Remove the go_default_library_protos filegroups using buildozer 2018-06-22 16:22:18 -07:00
BUILD Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00
README Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00
example_handler.go Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00
example_plugin.go Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00
plugin_watcher.go Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00
plugin_watcher_test.go Add hierarchy support for plugin directory 2018-06-25 17:32:18 -07:00

README

This folder contains a utility, pluginwatcher, for Kubelet to register
different types of node-level plugins such as device plugins or CSI plugins.
It discovers plugins by monitoring inotify events under the directory returned by
kubelet.getPluginsDir(). Lets refer this directory as PluginsSockDir.
For any discovered plugin, pluginwatcher issues Registration.GetInfo grpc call
to get plugin type, name and supported service API versions. For any registered plugin type,
pluginwatcher calls the registered callback function with the received plugin
name, supported service API versions, and the full socket path. The Kubelet
component that receives this callback can acknowledge or reject the plugin
according to its own logic, and use the socket path to establish its service
communication with any API version supported by the plugin.

Here are the general rules that Kubelet plugin developers should follow:
- Run as 'root' user. Currently creating socket under PluginsSockDir, a root owned directory, requires
  plugin process to be running as 'root'.

- Implements the Registration service specified in
  pkg/kubelet/apis/pluginregistration/v*/api.proto.

- The plugin name sent during Registration.GetInfo grpc should be unique
  for the given plugin type (CSIPlugin or DevicePlugin).

- The socket path needs to be unique within one directory, in normal case, 
  each plugin type has its own sub directory, but the design does support socket file
  under any sub directory of PluginSockDir.
 
- A plugin should clean up its own socket upon exiting or when a new instance
  comes up. A plugin should NOT remove any sockets belonging to other plugins.

- A plugin should make sure it has service ready for any supported service API
  version listed in the PluginInfo.

- For an example plugin implementation, take a look at example_plugin.go
  included in this directory.