Skip to content

Commit

Permalink
Avoid resetting the VF if the netns does not exist
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
zeeke committed Nov 28, 2024
1 parent b811f7a commit ad3c025
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cmd/sriov/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit ad3c025

Please sign in to comment.