Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix kube-ovn-cni crash for newly added nodes , due to old legacy event #4194

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading