Skip to content

Commit

Permalink
fix: del might panic if duplicate delete
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 7, 2021
1 parent 45bbfa9 commit 26a0272
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func (c *Controller) addIPSetMembers(setID, subnet, ip string) error {
}

func (c *Controller) removeIPSetMembers(setID, subnet, ip string) error {
if subnet == "" || ip == "" {
return nil
}
podSubnet, err := c.subnetsLister.Get(subnet)
if err != nil {
klog.Errorf("get subnet %s failed, %+v", subnet, err)
Expand Down
16 changes: 10 additions & 6 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,21 @@ func (csh cniServerHandler) handleDel(req *restful.Request, resp *restful.Respon
}
return
}

if k8serrors.IsNotFound(err) {
resp.WriteHeader(http.StatusNoContent)
return
}

// check if it's a sriov device
if pod != nil {
for _, container := range pod.Spec.Containers {
if _, ok := container.Resources.Requests[util.SRIOVResourceName]; ok {
podRequest.DeviceID = util.SRIOVResourceName
}
for _, container := range pod.Spec.Containers {
if _, ok := container.Resources.Requests[util.SRIOVResourceName]; ok {
podRequest.DeviceID = util.SRIOVResourceName
}
}

klog.Infof("delete port request %v", podRequest)
if podRequest.Provider == util.OvnProvider || podRequest.CniType == util.CniTypeName {
if pod.Annotations != nil && (podRequest.Provider == util.OvnProvider || podRequest.CniType == util.CniTypeName) {
subnet := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, podRequest.Provider)]
ip := pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, podRequest.Provider)]
if err = csh.Controller.removeIPSetMembers(LocalPodSet, subnet, ip); err != nil {
Expand Down

0 comments on commit 26a0272

Please sign in to comment.