mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00

Every device plugin is supposed to implement PluginInterfaceServer interface to be exposed as a gRPC service. But this functionality is common for all our device plugins and can be hidden in a Manager which manages all gRPC servers dynamically. The only mandatory functionality that needs to be provided by a device plugin and which differentiate one plugin from another is the code scanning the host for devices present on it. Refactor the internal deviceplugin package to accept only one mandatory method implementation from device plugins - Scan(). In addition to that a device plugin can optionally implement a PostAllocate() method which mutates responses returned by PluginInterfaceServer.Allocate() method. Also to narrow the gap between these device plugins and the kubevirt's collection the naming scheme for resources has been changed. Now device plugins provide a namespace for the device types they operate with. E.g. for resources in format "color.example.com/<color>" the namespace would be "color.example.com". So, the resource name "intel.com/fpga-region-fffffff" becomes "fpga.intel.com/region-fffffff".
67 lines
2.3 KiB
Go
67 lines
2.3 KiB
Go
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package deviceplugin
|
|
|
|
import (
|
|
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
|
)
|
|
|
|
// DeviceInfo contains information about device maintained by Device Plugin
|
|
type DeviceInfo struct {
|
|
State string
|
|
Nodes []string
|
|
Mounts []string
|
|
Envs map[string]string
|
|
}
|
|
|
|
// DeviceTree contains a tree-like structure of device type -> device ID -> device info.
|
|
type DeviceTree map[string]map[string]DeviceInfo
|
|
|
|
// NewDeviceTree creates an instance of DeviceTree
|
|
func NewDeviceTree() DeviceTree {
|
|
return make(map[string]map[string]DeviceInfo)
|
|
}
|
|
|
|
// AddDevice adds device info to DeviceTree.
|
|
func (tree DeviceTree) AddDevice(devType, id string, info DeviceInfo) {
|
|
if _, present := tree[devType]; !present {
|
|
tree[devType] = make(map[string]DeviceInfo)
|
|
}
|
|
tree[devType][id] = info
|
|
}
|
|
|
|
// Notifier receives updates from Scanner, detects changes and sends the
|
|
// detected changes to a channel given by the creator of a Notifier object.
|
|
type Notifier interface {
|
|
// Notify notifies manager with a device tree constructed by device
|
|
// plugin during scanning process.
|
|
Notify(DeviceTree)
|
|
}
|
|
|
|
// Scanner serves as an interface between Manager and a device plugin.
|
|
type Scanner interface {
|
|
// Scan scans the host for devices and sends all found devices to
|
|
// a Notifier instance. It's called only once for every device plugin by
|
|
// Manager in a goroutine and operates in an endless loop.
|
|
Scan(Notifier) error
|
|
}
|
|
|
|
// PostAllocator is an optional interface implemented by device plugins.
|
|
type PostAllocator interface {
|
|
// PostAllocate modifies responses returned by Allocate() by e.g.
|
|
// adding annotations consumed by CRI hooks to the responses.
|
|
PostAllocate(*pluginapi.AllocateResponse) error
|
|
}
|