Skip to content

Commit

Permalink
Fix pod host propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Oct 12, 2018
1 parent fb96fe0 commit 0c394e6
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions render/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var PodRenderer = Memoise(ConditionalRenderer(renderKubernetesTopologies,
},
MakeReduce(
PropagateSingleMetrics(report.Container,
MakeMap(propagateHostID,
MakeMap(propagatePodHost,
Map2Parent{topologies: []string{report.Pod}, noParentsPseudoID: UnmanagedID,
chainRenderer: MakeFilter(
ComposeFilterFuncs(
Expand All @@ -70,21 +70,25 @@ var PodRenderer = Memoise(ConditionalRenderer(renderKubernetesTopologies,
),
))

// Pods are not tagged with a Host ID, but their container children are.
// If n doesn't already have a host ID, copy it from one of the children
func propagateHostID(n report.Node) report.Node {
if _, found := n.Latest.Lookup(report.HostNodeID); found {
// Pods are not tagged with a Host parent, but their container children are.
// If n doesn't already have a host, copy it from one of the children
func propagatePodHost(n report.Node) report.Node {
if n.Topology != report.Pod {
return n
} else if _, found := n.Parents.Lookup(report.Host); found {
return n
}
var first *report.Node
done := false
n.Children.ForEach(func(child report.Node) {
if first == nil {
first = &child
if !done {
if hosts, found := child.Parents.Lookup(report.Host); found {
for _, h := range hosts {
n = n.WithParent(report.Host, h)
}
done = true
}
}
})
if first != nil {
n.Latest = n.Latest.Propagate(first.Latest, report.HostNodeID)
}
return n
}

Expand Down

0 comments on commit 0c394e6

Please sign in to comment.