add regiondevel mode to fpga_plugin

In the `af` mode the plugin announces AFUs and tells kubelet
to pass only AFU ports to containers.

In the `region` mode the plugin announces region interfaces and tells
kubelet to pass only AFU ports to containers.

In the `regiondevel` mode the plugin announces region interfaces and
tells kubelet to pass AFU ports and FME devices to containers, so the
conteainers have full access to the regions.
This commit is contained in:
Dmitry Rozhkov 2018-06-15 11:47:12 +03:00
parent 8f30aaa873
commit 979a8357c8
3 changed files with 57 additions and 5 deletions

View File

@ -33,8 +33,9 @@ import (
// Device Cache's mode of operation
const (
AfMode = "af"
RegionMode = "region"
AfMode = "af"
RegionMode = "region"
RegionDevelMode = "regiondevel"
)
const (
@ -54,7 +55,8 @@ type UpdateInfo struct {
type getDevMapFunc func(devices []device) map[string]map[string]deviceplugin.DeviceInfo
func getRegionMap(devices []device) map[string]map[string]deviceplugin.DeviceInfo {
// getRegionMap returns mapping of region interface IDs to AF ports and FME devices
func getRegionDevelMap(devices []device) map[string]map[string]deviceplugin.DeviceInfo {
regionMap := make(map[string]map[string]deviceplugin.DeviceInfo)
for _, dev := range devices {
@ -77,6 +79,30 @@ func getRegionMap(devices []device) map[string]map[string]deviceplugin.DeviceInf
return regionMap
}
// getRegionMap returns mapping of region interface IDs to AF ports only
func getRegionMap(devices []device) map[string]map[string]deviceplugin.DeviceInfo {
regionMap := make(map[string]map[string]deviceplugin.DeviceInfo)
for _, dev := range devices {
for _, region := range dev.regions {
if _, present := regionMap[region.interfaceID]; !present {
regionMap[region.interfaceID] = make(map[string]deviceplugin.DeviceInfo)
}
devNodes := make([]string, len(region.afus))
for num, afu := range region.afus {
devNodes[num] = afu.devNode
}
regionMap[region.interfaceID][region.id] = deviceplugin.DeviceInfo{
State: pluginapi.Healthy,
Nodes: devNodes,
}
}
}
return regionMap
}
// getAfuMap returns mapping of AFU IDs to AF ports
func getAfuMap(devices []device) map[string]map[string]deviceplugin.DeviceInfo {
afuMap := make(map[string]map[string]deviceplugin.DeviceInfo)
@ -138,6 +164,8 @@ func NewCache(sysfsDir string, devfsDir string, mode string, ch chan<- UpdateInf
getDevMap = getAfuMap
case RegionMode:
getDevMap = getRegionMap
case RegionDevelMode:
getDevMap = getRegionDevelMap
default:
return nil, fmt.Errorf("Wrong mode: '%s'", mode)
}

View File

@ -65,6 +65,9 @@ func TestNewCache(t *testing.T) {
{
mode: RegionMode,
},
{
mode: RegionDevelMode,
},
{
mode: "unparsable",
expectedErr: true,
@ -119,7 +122,7 @@ func getDevices() []device {
}
}
func TestGetRegionMap(t *testing.T) {
func TestGetRegionDevelMap(t *testing.T) {
expected := map[string]map[string]deviceplugin.DeviceInfo{
"ce48969398f05f33946d560708be108a": {
"intel-fpga-fme.0": {
@ -133,6 +136,26 @@ func TestGetRegionMap(t *testing.T) {
},
}
result := getRegionDevelMap(getDevices())
if !reflect.DeepEqual(result, expected) {
t.Error("Got unexpected result: ", result)
}
}
func TestGetRegionMap(t *testing.T) {
expected := map[string]map[string]deviceplugin.DeviceInfo{
"ce48969398f05f33946d560708be108a": {
"intel-fpga-fme.0": {
State: pluginapi.Healthy,
Nodes: []string{"/dev/intel-fpga-port.0"},
},
"intel-fpga-fme.1": {
State: pluginapi.Healthy,
Nodes: []string{"/dev/intel-fpga-port.1"},
},
},
}
result := getRegionMap(getDevices())
if !reflect.DeepEqual(result, expected) {
t.Error("Got unexpected result: ", result)

View File

@ -119,7 +119,8 @@ func handleUpdate(dms map[string]*deviceManager, updateInfo devicecache.UpdateIn
func main() {
var mode string
flag.StringVar(&mode, "mode", string(devicecache.AfMode), fmt.Sprintf("device plugin mode: '%s' (default) or '%s'", devicecache.AfMode, devicecache.RegionMode))
flag.StringVar(&mode, "mode", string(devicecache.AfMode),
fmt.Sprintf("device plugin mode: '%s' (default), '%s' or '%s'", devicecache.AfMode, devicecache.RegionMode, devicecache.RegionDevelMode))
flag.Parse()
updatesCh := make(chan devicecache.UpdateInfo)