From 95fcfd38e97e8e0758c42116cbbfa4e46840eef2 Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Thu, 28 Nov 2024 18:36:35 +0100 Subject: [PATCH] Avoid resetting the VF if the netns does not exist The VF might have been assigned to another running Pod if the network namespace is not present. In cases like this, resetting the VF might break the configuration of the running Pod. The above scenario might occur when the IPAM plugin takes a lot of time to complete, and the CmdDel gets called multiple times. Check if the namespace is still present before resetting the VF Signed-off-by: Andrea Panattoni --- cmd/sriov/main.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/cmd/sriov/main.go b/cmd/sriov/main.go index 3be92070..e355e32c 100644 --- a/cmd/sriov/main.go +++ b/cmd/sriov/main.go @@ -270,19 +270,10 @@ func cmdDel(args *skel.CmdArgs) error { sm := sriov.NewSriovManager() - logging.Debug("Reset VF configuration", - "func", "cmdDel", - "netConf.DeviceID", netConf.DeviceID) - /* ResetVFConfig resets a VF administratively. We must run ResetVFConfig - before ReleaseVF because some drivers will error out if we try to - reset netdev VF with trust off. So, reset VF MAC address via PF first. - */ - if err := sm.ResetVFConfig(netConf); err != nil { - return fmt.Errorf("cmdDel() error reseting VF: %q", err) - } + var netns ns.NetNS if !netConf.DPDKMode { - netns, err := ns.GetNS(args.Netns) + netns, err = ns.GetNS(args.Netns) if err != nil { // according to: // https://github.com/kubernetes/kubernetes/issues/43014#issuecomment-287164444 @@ -301,7 +292,20 @@ func cmdDel(args *skel.CmdArgs) error { return fmt.Errorf("failed to open netns %s: %q", netns, err) } defer netns.Close() + } + logging.Debug("Reset VF configuration", + "func", "cmdDel", + "netConf.DeviceID", netConf.DeviceID) + /* ResetVFConfig resets a VF administratively. We must run ResetVFConfig + before ReleaseVF because some drivers will error out if we try to + reset netdev VF with trust off. So, reset VF MAC address via PF first. + */ + if err := sm.ResetVFConfig(netConf); err != nil { + return fmt.Errorf("cmdDel() error reseting VF: %q", err) + } + + if !netConf.DPDKMode { logging.Debug("Release the VF", "func", "cmdDel", "netConf.DeviceID", netConf.DeviceID,