Skip to content

Commit

Permalink
fix kube-ovn-cni crash for newly added nodes , due to old legacy even…
Browse files Browse the repository at this point in the history
…t in deleteNodeQueue

Signed-off-by: clyi <[email protected]>
  • Loading branch information
changluyi committed Jun 20, 2024
1 parent ff0a7c5 commit a5321ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Controller struct {
addOrUpdatePodQueue workqueue.RateLimitingInterface
deletePodQueue workqueue.RateLimitingInterface
deletingPodObjMap *sync.Map
deletingNodeObjMap *sync.Map
updatePodSecurityQueue workqueue.RateLimitingInterface
podKeyMutex keymutex.KeyMutex

Expand Down Expand Up @@ -298,13 +299,14 @@ func Run(ctx context.Context, config *Configuration) {
numKeyLocks = config.WorkerNum * 2
}
controller := &Controller{
config: config,
vpcs: &sync.Map{},
podSubnetMap: &sync.Map{},
deletingPodObjMap: &sync.Map{},
ovnLegacyClient: ovs.NewLegacyClient(config.OvnTimeout),
ipam: ovnipam.NewIPAM(),
namedPort: NewNamedPort(),
config: config,
vpcs: &sync.Map{},
podSubnetMap: &sync.Map{},
deletingPodObjMap: &sync.Map{},
deletingNodeObjMap: &sync.Map{},
ovnLegacyClient: ovs.NewLegacyClient(config.OvnTimeout),
ipam: ovnipam.NewIPAM(),
namedPort: NewNamedPort(),

vpcsLister: vpcInformer.Lister(),
vpcSynced: vpcInformer.Informer().HasSynced,
Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (c *Controller) enqueueDeleteNode(obj interface{}) {
return
}
klog.V(3).Infof("enqueue delete node %s", key)

n := obj.(*v1.Node)
c.deletingNodeObjMap.Store(key, n)
c.deleteNodeQueue.Add(key)
}

Expand Down Expand Up @@ -173,6 +176,7 @@ func (c *Controller) processNextDeleteNodeWorkItem() bool {
return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error())
}
c.deleteNodeQueue.Forget(obj)
c.deletingNodeObjMap.Delete(key)
return nil
}(obj)
if err != nil {
Expand Down Expand Up @@ -472,6 +476,17 @@ func (c *Controller) handleDeleteNode(key string) error {
defer func() { _ = c.nodeKeyMutex.UnlockKey(key) }()
klog.Infof("handle delete node %s", key)

nodeObj, ok := c.deletingNodeObjMap.Load(key)
if !ok {
return nil
}
node := nodeObj.(*v1.Node)
n, _ := c.nodesLister.Get(key)
if n != nil && n.UID != node.UID {
klog.Warningf("Node %s is adding, skip the node delete handler, but it may leave some gc resources behind", key)
return nil
}

portName := util.NodeLspName(key)
klog.Infof("delete logical switch port %s", portName)
if err := c.OVNNbClient.DeleteLogicalSwitchPort(portName); err != nil {
Expand Down

0 comments on commit a5321ae

Please sign in to comment.