Skip to content

Commit

Permalink
Remove edges from graph for deleted objects (#326)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Aug 29, 2024
1 parent 0048d74 commit 247f0a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pkg/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ func (g *ObjectGraph) render(src kmapi.OID) (*runtime.RawExtension, error) {
}, nil
}

func (g *ObjectGraph) Delete(src kmapi.OID) {
g.m.Lock()
defer g.m.Unlock()

for lbl, connMap := range g.Edges[src] {
for to := range connMap {
g.delEdge(to, src, lbl)
}
}

delete(g.Edges, src)
delete(g.IDs, src)
}

func (g *ObjectGraph) Update(src kmapi.OID, connsPerLabel map[kmapi.EdgeLabel]ksets.OID) {
g.m.Lock()
defer g.m.Unlock()
Expand Down
9 changes: 8 additions & 1 deletion pkg/graph/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
var obj unstructured.Unstructured
obj.SetGroupVersionKind(gvk)
if err := r.Get(context.TODO(), req.NamespacedName, &obj); err != nil {
log.Error(err, "unable to fetch", "group", r.R.Group, "kind", r.R.Kind)
oid := kmapi.ObjectID{
Group: gvk.Group,
Kind: gvk.Kind,
Namespace: req.Namespace,
Name: req.Name,
}
objGraph.Delete(oid.OID())

// we'll ignore not-found errors, since they can't be fixed by an immediate
// requeue (we'll need to wait for a new notification), and we can get them
// on deleted requests.
Expand Down

0 comments on commit 247f0a9

Please sign in to comment.