Documentation
¶
Overview ¶
Package deviceplugin is the kubelet device plugin of the node-agent. It advertises one extended resource, cybericebox.com/tun, and a pod that requests it gets /dev/net/tun passed by the kubelet and nothing else from the host: that is how the `extended` device profile reaches tun without a privileged container or a hostPath.
Index ¶
- Constants
- type Plugin
- func (p *Plugin) Allocate(_ context.Context, req *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error)
- func (p *Plugin) GetDevicePluginOptions(context.Context, *pluginapi.Empty) (*pluginapi.DevicePluginOptions, error)
- func (p *Plugin) GetPreferredAllocation(context.Context, *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error)
- func (p *Plugin) ListAndWatch(_ *pluginapi.Empty, stream pluginapi.DevicePlugin_ListAndWatchServer) error
- func (p *Plugin) PreStartContainer(context.Context, *pluginapi.PreStartContainerRequest) (*pluginapi.PreStartContainerResponse, error)
- func (p *Plugin) Serve(ctx context.Context) error
- func (p *Plugin) SetCheckPath(path string)
- func (p *Plugin) SetHostPath(path string)
Constants ¶
const TUNDevice = "/dev/net/tun"
TUNDevice is the host path of the tun device the plugin hands out; the container sees it at the same path.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct {
pluginapi.UnimplementedDevicePluginServer
Resource string // cybericebox.com/tun
Dir string // the kubelet's device-plugins directory
Slots int
HostPath string // the device on the host as the kubelet sees it (what a container gets); default TUNDevice
// CheckPath is what THIS process looks at to see that the device exists on the host. A container's /dev is minimal and has no tun
// even when the host does, so the node-agent checks the kernel's sysfs entry of the tun misc device, /sys/class/misc/tun/dev
// (present exactly when the tun module is loaded; sysfs shows the host's kernel in a container, read-only, no extra mount).
// Any path there only has to exist. Empty: HostPath, which must then be a character device.
CheckPath string
Interval time.Duration
Log logr.Logger
// contains filtered or unexported fields
}
Plugin serves one resource. Its devices are interchangeable virtual slots (the same /dev/net/tun for each), so a node can run as many extended devices as it has slots; the count only bounds that.
func (*Plugin) Allocate ¶
func (p *Plugin) Allocate(_ context.Context, req *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error)
Allocate answers with the tun device for every container request: that is all the kubelet passes.
func (*Plugin) GetDevicePluginOptions ¶
func (*Plugin) GetPreferredAllocation ¶
func (p *Plugin) GetPreferredAllocation(context.Context, *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error)
func (*Plugin) ListAndWatch ¶
func (p *Plugin) ListAndWatch(_ *pluginapi.Empty, stream pluginapi.DevicePlugin_ListAndWatchServer) error
ListAndWatch sends the devices, and again whenever the health of the host device changes (it appears or goes away).
func (*Plugin) PreStartContainer ¶
func (p *Plugin) PreStartContainer(context.Context, *pluginapi.PreStartContainerRequest) (*pluginapi.PreStartContainerResponse, error)
func (*Plugin) Serve ¶
Serve listens on the plugin's socket in the kubelet directory and registers with the kubelet; it registers again when the kubelet restarts (its socket is replaced). It returns when ctx ends.
func (*Plugin) SetCheckPath ¶
SetCheckPath changes where the plugin checks the device exists (tests move it).
func (*Plugin) SetHostPath ¶
SetHostPath changes the device the plugin looks for (tests move it); the check path follows unless one was set.