Skip to content

Commit

Permalink
Filter NIC by SRIOV_DEVICE_NAME_FILTER
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Sep 14, 2023
1 parent e036918 commit 27d1c74
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions test/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -92,33 +94,48 @@ func DiscoverSriov(clients *testclient.ClientSet, operatorNamespace string) (*En

// FindOneSriovDevice retrieves a valid sriov device for the given node.
func (n *EnabledNodes) FindOneSriovDevice(node string) (*sriovv1.InterfaceExt, error) {
s, ok := n.States[node]
ret, err := n.FindSriovDevices(node)
if err != nil {
return nil, err
}

if len(ret) == 0 {
return nil, fmt.Errorf("unable to find sriov devices in node %s", node)
}

return ret[0], nil
}

// FindSriovDevices retrieves all valid sriov devices for the given node, filtered by `SRIOV_DEVICE_NAME_FILTER` environment variable.
func (n *EnabledNodes) FindSriovDevices(node string) ([]*sriovv1.InterfaceExt, error) {
devices, err := n.FindSriovDevicesIgnoreFilters(node)
if err != nil {
return nil, err
}

sriovDeviceNameFilter, ok := os.LookupEnv("SRIOV_DEVICE_NAME_FILTER")
if !ok {
return nil, fmt.Errorf("node %s not found", node)
return devices, nil
}
for _, itf := range s.Status.Interfaces {
if IsPFDriverSupported(itf.Driver) && sriovv1.IsSupportedDevice(itf.DeviceID) {
// Skip mlx interfaces if secure boot is enabled
// TODO: remove this when mlx support secure boot/lockdown mode
if itf.Vendor == mlxVendorID && n.IsSecureBootEnabled[node] {
continue
}

// if the sriov is not enable in the kernel for intel nic the totalVF will be 0 so we skip the device
// That is not the case for Mellanox devices that will report 0 until we configure the sriov interfaces
// with the mstconfig package
if itf.Vendor == intelVendorID && itf.TotalVfs == 0 {
continue
}
filteredDevices := []*sriovv1.InterfaceExt{}
for _, device := range devices {

Check failure on line 122 in test/util/cluster/cluster.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

unnecessary leading newline (whitespace)

return &itf, nil
match, err := regexp.MatchString(sriovDeviceNameFilter, device.Name)
if err != nil {
return nil, err
}

if match {
filteredDevices = append(filteredDevices, device)
}
}
return nil, fmt.Errorf("unable to find sriov devices in node %s", node)

return filteredDevices, nil
}

// FindSriovDevices retrieves all valid sriov devices for the given node.
func (n *EnabledNodes) FindSriovDevices(node string) ([]*sriovv1.InterfaceExt, error) {
func (n *EnabledNodes) FindSriovDevicesIgnoreFilters(node string) ([]*sriovv1.InterfaceExt, error) {
devices := []*sriovv1.InterfaceExt{}
s, ok := n.States[node]
if !ok {
Expand Down

0 comments on commit 27d1c74

Please sign in to comment.