diff --git a/probe/host/tagger.go b/probe/host/tagger.go index 88eee393ad..601cb9bd0f 100644 --- a/probe/host/tagger.go +++ b/probe/host/tagger.go @@ -33,7 +33,7 @@ func (t Tagger) Tag(r report.Report) (report.Report, error) { // and as such do their own host tagging. for _, topology := range []report.Topology{r.Process, r.Container, r.ContainerImage, r.Host, r.Pod} { for _, node := range topology.Nodes { - topology.AddNode(node.WithLatests(metadata).WithParents(parents)) + topology.ReplaceNode(node.WithLatests(metadata).WithParents(parents)) } } return r, nil diff --git a/probe/topology_tagger.go b/probe/topology_tagger.go index 49dfc3bb3e..3f9cb61799 100644 --- a/probe/topology_tagger.go +++ b/probe/topology_tagger.go @@ -18,7 +18,7 @@ func (topologyTagger) Name() string { return "Topology" } func (topologyTagger) Tag(r report.Report) (report.Report, error) { r.WalkNamedTopologies(func(name string, t *report.Topology) { for _, node := range t.Nodes { - t.AddNode(node.WithTopology(name)) + t.ReplaceNode(node.WithTopology(name)) } }) return r, nil diff --git a/report/topology.go b/report/topology.go index df08220a70..fea555332a 100644 --- a/report/topology.go +++ b/report/topology.go @@ -113,6 +113,13 @@ func (t Topology) AddNode(node Node) Topology { return t } +// ReplaceNode adds node to the topology under key nodeID; if a +// node already exists for this key, node replaces that node. +// Like AddNode, it mutates the Topology +func (t Topology) ReplaceNode(node Node) { + t.Nodes[node.ID] = node +} + // GetShape returns the current topology shape, or the default if there isn't one. func (t Topology) GetShape() string { if t.Shape == "" {