fpga: use CDI to run hooks

This commit is contained in:
Ed Bartosh 2024-05-16 18:32:53 +03:00
parent 992fdc6a6c
commit d245b2609d
3 changed files with 33 additions and 7 deletions

View File

@ -23,6 +23,7 @@ import (
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
cdispec "tags.cncf.io/container-device-interface/specs-go"
)
func TestNewDevicePluginDFL(t *testing.T) {
@ -187,6 +188,12 @@ func TestGetRegionDevelTreeDFL(t *testing.T) {
func TestGetRegionTreeDFL(t *testing.T) {
expected := dpapi.NewDeviceTree()
hooks := []*cdispec.Hook{
{
HookName: HookName,
Path: HookPath,
},
}
nodes := []pluginapi.DeviceSpec{
{
HostPath: "/dev/dfl-port.0",
@ -194,7 +201,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "region1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "region1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, hooks))
nodes = []pluginapi.DeviceSpec{
{
@ -208,7 +215,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "region2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "region2", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, hooks))
nodes = []pluginapi.DeviceSpec{
{
@ -222,7 +229,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-"+unhealthyInterfaceID, "region3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-"+unhealthyInterfaceID, "region3", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil, nil, hooks))
result := getRegionTree(getDevicesDFL())
if !reflect.DeepEqual(result, expected) {

View File

@ -24,6 +24,7 @@ import (
"k8s.io/klog/v2"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
cdispec "tags.cncf.io/container-device-interface/specs-go"
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
@ -50,6 +51,10 @@ const (
// Period of device scans.
scanPeriod = 5 * time.Second
// CDI hook attributes.
HookName = "prestart"
HookPath = "/opt/intel/fpga-sw/intel-fpga-crihook"
)
type newPortFunc func(fname string) (fpga.Port, error)
@ -112,7 +117,14 @@ func getRegionTree(devices []device) dpapi.DeviceTree {
}
}
regionTree.AddDevice(devType, region.id, dpapi.NewDeviceInfo(health, devNodes, nil, nil, nil, nil))
hooks := []*cdispec.Hook{
{
HookName: HookName,
Path: HookPath,
},
}
regionTree.AddDevice(devType, region.id, dpapi.NewDeviceInfo(health, devNodes, nil, nil, nil, hooks))
}
}

View File

@ -23,6 +23,7 @@ import (
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
cdispec "tags.cncf.io/container-device-interface/specs-go"
)
func TestNewDevicePluginOPAE(t *testing.T) {
@ -167,6 +168,12 @@ func TestGetRegionDevelTreeOPAE(t *testing.T) {
func TestGetRegionTreeOPAE(t *testing.T) {
expected := dpapi.NewDeviceTree()
hooks := []*cdispec.Hook{
{
HookName: HookName,
Path: HookPath,
},
}
nodes := []pluginapi.DeviceSpec{
{
HostPath: "/dev/intel-fpga-port.0",
@ -174,7 +181,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "intel-fpga-fme.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "intel-fpga-fme.0", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, hooks))
nodes = []pluginapi.DeviceSpec{
{
@ -183,7 +190,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "intel-fpga-fme.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-ce48969398f05f33946d560708be108a", "intel-fpga-fme.1", dpapi.NewDeviceInfo(pluginapi.Healthy, nodes, nil, nil, nil, hooks))
nodes = []pluginapi.DeviceSpec{
{
@ -192,7 +199,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
Permissions: "rw",
},
}
expected.AddDevice(regionMode+"-"+unhealthyInterfaceID, "intel-fpga-fme.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil, nil, nil))
expected.AddDevice(regionMode+"-"+unhealthyInterfaceID, "intel-fpga-fme.2", dpapi.NewDeviceInfo(pluginapi.Unhealthy, nodes, nil, nil, nil, hooks))
result := getRegionTree(getDevicesOPAE())
if !reflect.DeepEqual(result, expected) {