Skip to content

Commit

Permalink
fix: if sriov device, do not delete the host nic
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Jul 28, 2020
1 parent baf0d8c commit e64c613
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func cmdDel(args *skel.CmdArgs) error {
ContainerID: args.ContainerID,
NetNs: args.Netns,
Provider: netConf.Provider,
DeviceID: netConf.DeviceID,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (csh cniServerHandler) handleDel(req *restful.Request, resp *restful.Respon

klog.Infof("delete port request %v", podRequest)
if podRequest.Provider == util.OvnProvider {
err = csh.deleteNic(podRequest.PodName, podRequest.PodNamespace, podRequest.ContainerID)
err = csh.deleteNic(podRequest.PodName, podRequest.PodNamespace, podRequest.ContainerID, podRequest.DeviceID)
if err != nil {
errMsg := fmt.Errorf("del nic failed %v", err)
klog.Error(errMsg)
Expand Down
23 changes: 12 additions & 11 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, netns, container
return nil
}

func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID string) error {
func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID, deviceID string) error {
hostNicName, _ := generateNicName(containerID)
// Remove ovs port
output, err := ovs.Exec("--if-exists", "--with-iface", "del-port", "br-int", hostNicName)
Expand All @@ -77,18 +77,19 @@ func (csh cniServerHandler) deleteNic(podName, podNamespace, containerID string)
return err
}

hostLink, err := netlink.LinkByName(hostNicName)
if err != nil {
// If link already not exists, return quietly
if _, ok := err.(netlink.LinkNotFoundError); ok {
return nil
if deviceID == "" {
hostLink, err := netlink.LinkByName(hostNicName)
if err != nil {
// If link already not exists, return quietly
if _, ok := err.(netlink.LinkNotFoundError); ok {
return nil
}
return fmt.Errorf("find host link %s failed %v", hostNicName, err)
}
if err = netlink.LinkDel(hostLink); err != nil {
return fmt.Errorf("delete host link %s failed %v", hostLink, err)
}
return fmt.Errorf("find host link %s failed %v", hostNicName, err)
}
if err = netlink.LinkDel(hostLink); err != nil {
return fmt.Errorf("delete host link %s failed %v", hostLink, err)
}

return nil
}

Expand Down

0 comments on commit e64c613

Please sign in to comment.