/
parents.go
68 lines (64 loc) · 1.53 KB
/
parents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package detailed
import (
"github.com/weaveworks/scope/report"
)
// Parent is the information needed to build a link to the parent of a Node.
type Parent struct {
ID string `json:"id"`
Label string `json:"label"`
TopologyID string `json:"topologyId"`
}
// parent topologies, in the order we want to show them
var parentTopologies = []string{
report.Container,
report.ContainerImage,
report.Pod,
report.Deployment,
report.DaemonSet,
report.StatefulSet,
report.CronJob,
report.Service,
report.ECSTask,
report.ECSService,
report.SwarmService,
report.Host,
}
// Parents renders the parents of this report.Node, which have been aggregated
// from the probe reports.
func Parents(r report.Report, n report.Node) []Parent {
if n.Parents.Size() == 0 {
return nil
}
result := make([]Parent, 0, n.Parents.Size())
for _, topologyID := range parentTopologies {
topology, ok := r.Topology(topologyID)
if !ok {
continue
}
apiTopologyID, ok := primaryAPITopology[topologyID]
if !ok {
continue
}
parents, _ := n.Parents.Lookup(topologyID)
for _, id := range parents {
if topologyID == n.Topology && id == n.ID {
continue
}
parentNode, ok := topology.Nodes[id]
if !ok {
parentNode = report.MakeNode(id).WithTopology(topologyID)
}
if summary, ok := MakeBasicNodeSummary(r, parentNode); ok {
result = append(result, Parent{
ID: summary.ID,
Label: summary.Label,
TopologyID: apiTopologyID,
})
}
}
}
if len(result) == 0 {
return nil
}
return result
}