Skip to content

Commit

Permalink
Check that PF Link is up when calling NeedToUpdateSriov()
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilis Remmas <vremmas@nvidia.com>
  • Loading branch information
vasrem committed Jan 17, 2024
1 parent 39f3313 commit 4a9bd4b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/vishvananda/netlink"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -247,6 +248,13 @@ func NeedToUpdateSriov(ifaceSpec *Interface, ifaceStatus *InterfaceExt) bool {
log.V(2).Info("NeedToUpdateSriov(): NumVfs needs update", "desired", ifaceSpec.NumVfs, "current", ifaceStatus.NumVfs)
return true
}

var linkUp netlink.LinkOperState = netlink.OperUp
if ifaceStatus.LinkStatus != linkUp.String() {
log.V(2).Info("NeedToUpdateSriov(): PF link status needs update", "desired", linkUp.String(), "current", ifaceStatus.LinkStatus)
return true
}

if ifaceSpec.NumVfs > 0 {
for _, vfStatus := range ifaceStatus.VFs {
ingroup := false
Expand Down
57 changes: 57 additions & 0 deletions pkg/plugins/generic/generic_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down Expand Up @@ -114,6 +115,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down Expand Up @@ -164,6 +166,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand All @@ -185,6 +188,56 @@ var _ = Describe("Generic plugin", func() {
Expect(needDrain).To(BeTrue())
})

It("should drain because PF link is not up", func() {
networkNodeState := &sriovnetworkv1.SriovNetworkNodeState{
Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{
Interfaces: sriovnetworkv1.Interfaces{{
PciAddress: "0000:00:00.0",
NumVfs: 1,
Mtu: 1500,
VfGroups: []sriovnetworkv1.VfGroup{{
DeviceType: "netdevice",
PolicyName: "policy-1",
ResourceName: "resource-1",
VfRange: "0-1",
Mtu: 1500,
}}}},
},
Status: sriovnetworkv1.SriovNetworkNodeStateStatus{
Interfaces: sriovnetworkv1.InterfaceExts{{
PciAddress: "0000:00:00.0",
NumVfs: 1,
TotalVfs: 1,
DeviceID: "1015",
Vendor: "15b3",
Name: "sriovif1",
Mtu: 1500,
Mac: "0c:42:a1:55:ee:46",
Driver: "mlx5_core",
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "IB",
LinkStatus: "down",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Vendor: "15b3",
VfID: 0,
Name: "sriovif1v0",
Mtu: 1500,
Driver: "mlx5_core",
}},
}},
},
}

hostHelper.EXPECT().WriteSwitchdevConfFile(networkNodeState, map[string]bool{"0000:00:00.0": false}).Return(false, nil)
needDrain, needReboot, err := genericPlugin.OnNodeStateChange(networkNodeState)
Expect(err).ToNot(HaveOccurred())
Expect(needReboot).To(BeFalse())
Expect(needDrain).To(BeTrue())
})

It("should drain because driver has changed on VF of type netdevice", func() {
networkNodeState := &sriovnetworkv1.SriovNetworkNodeState{
Spec: sriovnetworkv1.SriovNetworkNodeStateSpec{
Expand Down Expand Up @@ -214,6 +267,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down Expand Up @@ -264,6 +318,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down Expand Up @@ -321,6 +376,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "ETH",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down Expand Up @@ -370,6 +426,7 @@ var _ = Describe("Generic plugin", func() {
EswitchMode: "legacy",
LinkSpeed: "25000 Mb/s",
LinkType: "IB",
LinkStatus: "up",
VFs: []sriovnetworkv1.VirtualFunction{{
PciAddress: "0000:00:00.1",
DeviceID: "1016",
Expand Down

0 comments on commit 4a9bd4b

Please sign in to comment.