Make node removal conditional in processGraphChanges

This commit is contained in:
Jordan Liggitt 2020-07-08 01:54:03 -04:00
parent ac8d419b4c
commit b8d7ecf73b

View File

@ -679,24 +679,29 @@ func (gb *GraphBuilder) processGraphChanges() bool {
klog.V(5).Infof("%v doesn't exist in the graph, this shouldn't happen", accessor.GetUID()) klog.V(5).Infof("%v doesn't exist in the graph, this shouldn't happen", accessor.GetUID())
return true return true
} }
// removeNode updates the graph
gb.removeNode(existingNode) removeExistingNode := true
existingNode.dependentsLock.RLock()
defer existingNode.dependentsLock.RUnlock() if removeExistingNode {
if len(existingNode.dependents) > 0 { // removeNode updates the graph
gb.absentOwnerCache.Add(identityFromEvent(event, accessor)) gb.removeNode(existingNode)
} existingNode.dependentsLock.RLock()
for dep := range existingNode.dependents { defer existingNode.dependentsLock.RUnlock()
gb.attemptToDelete.Add(dep) if len(existingNode.dependents) > 0 {
} gb.absentOwnerCache.Add(identityFromEvent(event, accessor))
for _, owner := range existingNode.owners { }
ownerNode, found := gb.uidToNode.Read(owner.UID) for dep := range existingNode.dependents {
if !found || !ownerNode.isDeletingDependents() { gb.attemptToDelete.Add(dep)
continue }
for _, owner := range existingNode.owners {
ownerNode, found := gb.uidToNode.Read(owner.UID)
if !found || !ownerNode.isDeletingDependents() {
continue
}
// this is to let attempToDeleteItem check if all the owner's
// dependents are deleted, if so, the owner will be deleted.
gb.attemptToDelete.Add(ownerNode)
} }
// this is to let attempToDeleteItem check if all the owner's
// dependents are deleted, if so, the owner will be deleted.
gb.attemptToDelete.Add(ownerNode)
} }
} }
return true return true