Skip to content

Commit

Permalink
Avoid reconfiguring unmentioned DPDK VFs
Browse files Browse the repository at this point in the history
If a Virtual Function is configured with a DPDK driver (e.g. `vfio-pci`) and it is not
referred by any SriovNetworkNodePolicy, `NeedToUpdateSriov` function must not
trigger a  reconfiguration. This may happen if a PF is configured by multiple policies
(via PF partitioning) and a policy is deleted by the user. In these cases, the VF is not
reconfigured [1] and a drain loop is started

refs:
[1] https://github.com/k8snetworkplumbingwg/sriov-network-operator/blob/5f3c4e903f789aa177fe54686efd6c18576b7ab1/pkg/host/internal/sriov/sriov.go#L457

Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Jun 10, 2024
1 parent a767d33 commit 349b8ef
Showing 2 changed files with 72 additions and 7 deletions.
6 changes: 2 additions & 4 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
@@ -332,10 +332,8 @@ func NeedToUpdateSriov(ifaceSpec *Interface, ifaceStatus *InterfaceExt) bool {
break
}
}
if !ingroup && (StringInArray(vfStatus.Driver, vars.DpdkDrivers) || vfStatus.VdpaType != "") {
// need to reset VF if it is not a part of a group and:
// a. has DPDK driver loaded
// b. has VDPA device
if !ingroup && vfStatus.VdpaType != "" {
// need to reset VF if it is not a part of a group and has VDPA device
return true
}
}
73 changes: 70 additions & 3 deletions api/v1/helper_test.go
Original file line number Diff line number Diff line change
@@ -10,11 +10,10 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
intstrutil "k8s.io/apimachinery/pkg/util/intstr"

v1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"

Check failure on line 13 in api/v1/helper_test.go

GitHub Actions / Golangci-lint

File is not `goimports`-ed with -local github.com/k8snetworkplumbingwg/sriov-network-operator (goimports)
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
intstrutil "k8s.io/apimachinery/pkg/util/intstr"
)

var update = flag.Bool("updategolden", false, "update .golden files")
@@ -1054,3 +1053,71 @@ func TestSriovNetworkPoolConfig_MaxUnavailable(t *testing.T) {
})
}
}

func TestNeedToUpdateSriov(t *testing.T) {
type args struct {
ifaceSpec *v1.Interface
ifaceStatus *v1.InterfaceExt
}
tests := []struct {
name string
args args
want bool
}{
{
name: "number of VFs changed",
args: args{
ifaceSpec: &v1.Interface{NumVfs: 1},
ifaceStatus: &v1.InterfaceExt{NumVfs: 0},
},
want: true,
},
{
name: "no update",
args: args{
ifaceSpec: &v1.Interface{NumVfs: 1},
ifaceStatus: &v1.InterfaceExt{NumVfs: 1},
},
want: false,
},
{
name: "vfio-pci VF is not configured for any group",
args: args{
ifaceSpec: &v1.Interface{
NumVfs: 3,
VfGroups: []v1.VfGroup{
{
VfRange: "1-2",
DeviceType: consts.DeviceTypeNetDevice,
},
},
},
ifaceStatus: &v1.InterfaceExt{
NumVfs: 3,
VFs: []v1.VirtualFunction{
{
VfID: 0,
Driver: "vfio-pci",
},
{
VfID: 1,
Driver: "iavf",
},
{
VfID: 2,
Driver: "iavf",
},
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := v1.NeedToUpdateSriov(tt.args.ifaceSpec, tt.args.ifaceStatus); got != tt.want {
t.Errorf("NeedToUpdateSriov() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 349b8ef

Please sign in to comment.