mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
Replace virtual node with observed node if identity differs
If the graph contains a virtual node (because some child object referenced it in an OwnerRef), and a real informer event is observed for that uid at different coordinates, we want to fix the coordinates of the node in the graph to match the actual coordinates. The safe way to do this is to clone the node, replace the identity in the clone, then replace the node with the clone. Modifying the identity directly is not safe because it is accessed lock-free from many code paths. Replacing the node in the graph from processGraphChanges is safe because it is the only graph writer.
This commit is contained in:
@@ -61,6 +61,25 @@ type node struct {
|
||||
owners []metav1.OwnerReference
|
||||
}
|
||||
|
||||
// clone() must only be called from the single-threaded GraphBuilder.processGraphChanges()
|
||||
func (n *node) clone() *node {
|
||||
c := &node{
|
||||
identity: n.identity,
|
||||
dependents: make(map[*node]struct{}, len(n.dependents)),
|
||||
deletingDependents: n.deletingDependents,
|
||||
beingDeleted: n.beingDeleted,
|
||||
virtual: n.virtual,
|
||||
owners: make([]metav1.OwnerReference, 0, len(n.owners)),
|
||||
}
|
||||
for dep := range n.dependents {
|
||||
c.dependents[dep] = struct{}{}
|
||||
}
|
||||
for _, owner := range n.owners {
|
||||
c.owners = append(c.owners, owner)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// An object is on a one way trip to its final deletion if it starts being
|
||||
// deleted, so we only provide a function to set beingDeleted to true.
|
||||
func (n *node) markBeingDeleted() {
|
||||
|
||||
Reference in New Issue
Block a user