mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
fpga: use CDI to run hooks
This commit is contained in:
parent
992fdc6a6c
commit
d245b2609d
@ -23,6 +23,7 @@ import (
|
|||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
|
cdispec "tags.cncf.io/container-device-interface/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDevicePluginDFL(t *testing.T) {
|
func TestNewDevicePluginDFL(t *testing.T) {
|
||||||
@ -187,6 +188,12 @@ func TestGetRegionDevelTreeDFL(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetRegionTreeDFL(t *testing.T) {
|
func TestGetRegionTreeDFL(t *testing.T) {
|
||||||
expected := dpapi.NewDeviceTree()
|
expected := dpapi.NewDeviceTree()
|
||||||
|
hooks := []*cdispec.Hook{
|
||||||
|
{
|
||||||
|
HookName: HookName,
|
||||||
|
Path: HookPath,
|
||||||
|
},
|
||||||
|
}
|
||||||
nodes := []pluginapi.DeviceSpec{
|
nodes := []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
HostPath: "/dev/dfl-port.0",
|
HostPath: "/dev/dfl-port.0",
|
||||||
@ -194,7 +201,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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{
|
nodes = []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
@ -208,7 +215,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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{
|
nodes = []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
@ -222,7 +229,7 @@ func TestGetRegionTreeDFL(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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())
|
result := getRegionTree(getDevicesDFL())
|
||||||
if !reflect.DeepEqual(result, expected) {
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
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"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
||||||
@ -50,6 +51,10 @@ const (
|
|||||||
|
|
||||||
// Period of device scans.
|
// Period of device scans.
|
||||||
scanPeriod = 5 * time.Second
|
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)
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/fpga"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
|
cdispec "tags.cncf.io/container-device-interface/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewDevicePluginOPAE(t *testing.T) {
|
func TestNewDevicePluginOPAE(t *testing.T) {
|
||||||
@ -167,6 +168,12 @@ func TestGetRegionDevelTreeOPAE(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetRegionTreeOPAE(t *testing.T) {
|
func TestGetRegionTreeOPAE(t *testing.T) {
|
||||||
expected := dpapi.NewDeviceTree()
|
expected := dpapi.NewDeviceTree()
|
||||||
|
hooks := []*cdispec.Hook{
|
||||||
|
{
|
||||||
|
HookName: HookName,
|
||||||
|
Path: HookPath,
|
||||||
|
},
|
||||||
|
}
|
||||||
nodes := []pluginapi.DeviceSpec{
|
nodes := []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
HostPath: "/dev/intel-fpga-port.0",
|
HostPath: "/dev/intel-fpga-port.0",
|
||||||
@ -174,7 +181,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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{
|
nodes = []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
@ -183,7 +190,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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{
|
nodes = []pluginapi.DeviceSpec{
|
||||||
{
|
{
|
||||||
@ -192,7 +199,7 @@ func TestGetRegionTreeOPAE(t *testing.T) {
|
|||||||
Permissions: "rw",
|
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())
|
result := getRegionTree(getDevicesOPAE())
|
||||||
if !reflect.DeepEqual(result, expected) {
|
if !reflect.DeepEqual(result, expected) {
|
||||||
|
Loading…
Reference in New Issue
Block a user