parents.go 1.5 KB

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