From 4a9bd4b937bf922e12756a4b750aa4364d93b573 Mon Sep 17 00:00:00 2001 From: Vasilis Remmas Date: Wed, 17 Jan 2024 14:13:21 +0100 Subject: [PATCH] Check that PF Link is up when calling NeedToUpdateSriov() Signed-off-by: Vasilis Remmas --- api/v1/helper.go | 8 +++ pkg/plugins/generic/generic_plugin_test.go | 57 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/api/v1/helper.go b/api/v1/helper.go index ebdee446f0..e77a6ea468 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -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" @@ -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 diff --git a/pkg/plugins/generic/generic_plugin_test.go b/pkg/plugins/generic/generic_plugin_test.go index dd13e4e0a9..0fa195cf4b 100644 --- a/pkg/plugins/generic/generic_plugin_test.go +++ b/pkg/plugins/generic/generic_plugin_test.go @@ -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", @@ -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", @@ -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", @@ -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{ @@ -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", @@ -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", @@ -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", @@ -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",