Avoid marking virtual nodes as observed when they haven't been
Virtual nodes can be added to the GC graph in order to represent objects which have not been observed via an informer, but are referenced via ownerReferences. These virtual nodes are requeued into attemptToDelete until they are observed via an informer, or successfully verified absent via a live lookup. Previously, both of those code paths called markObserved() to stop requeuing into attemptToDelete. Because it is useful to know whether a particular node has been observed via a real informer event, this commit does the following: * adds a `virtual bool` attribute to graph events so we know which ones came from a real informer * limits the markObserved() call to the code path where a real informer event is observed * uses an alternative mechanism to stop requeueing into attemptToDelete when a virtual node is verified absent via a live lookup
This commit is contained in:
@@ -61,6 +61,8 @@ const (
|
||||
)
|
||||
|
||||
type event struct {
|
||||
// virtual indicates this event did not come from an informer, but was constructed artificially
|
||||
virtual bool
|
||||
eventType eventType
|
||||
obj interface{}
|
||||
// the update event comes with an old object, but it's not used by the garbage collector.
|
||||
@@ -329,6 +331,7 @@ func DefaultIgnoredResources() map[schema.GroupResource]struct{} {
|
||||
func (gb *GraphBuilder) enqueueVirtualDeleteEvent(ref objectReference) {
|
||||
gv, _ := schema.ParseGroupVersion(ref.APIVersion)
|
||||
gb.graphChanges.Add(&event{
|
||||
virtual: true,
|
||||
eventType: deleteEvent,
|
||||
gvk: gv.WithKind(ref.Kind),
|
||||
obj: &metaonly.MetadataOnlyObject{
|
||||
@@ -545,10 +548,10 @@ func (gb *GraphBuilder) processGraphChanges() bool {
|
||||
utilruntime.HandleError(fmt.Errorf("cannot access obj: %v", err))
|
||||
return true
|
||||
}
|
||||
klog.V(5).Infof("GraphBuilder process object: %s/%s, namespace %s, name %s, uid %s, event type %v", event.gvk.GroupVersion().String(), event.gvk.Kind, accessor.GetNamespace(), accessor.GetName(), string(accessor.GetUID()), event.eventType)
|
||||
klog.V(5).Infof("GraphBuilder process object: %s/%s, namespace %s, name %s, uid %s, event type %v, virtual=%v", event.gvk.GroupVersion().String(), event.gvk.Kind, accessor.GetNamespace(), accessor.GetName(), string(accessor.GetUID()), event.eventType, event.virtual)
|
||||
// Check if the node already exists
|
||||
existingNode, found := gb.uidToNode.Read(accessor.GetUID())
|
||||
if found {
|
||||
if found && !event.virtual && !existingNode.isObserved() {
|
||||
// this marks the node as having been observed via an informer event
|
||||
// 1. this depends on graphChanges only containing add/update events from the actual informer
|
||||
// 2. this allows things tracking virtual nodes' existence to stop polling and rely on informer events
|
||||
|
Reference in New Issue
Block a user