diff --git a/probe/kubernetes/pod.go b/probe/kubernetes/pod.go index f204d69c26..6d3cf87198 100644 --- a/probe/kubernetes/pod.go +++ b/probe/kubernetes/pod.go @@ -15,6 +15,7 @@ const ( PodName = "kubernetes_pod_name" PodCreated = "kubernetes_pod_created" PodContainerIDs = "kubernetes_pod_container_ids" + PodState = "kubernetes_pod_state" ServiceIDs = "kubernetes_service_ids" ) @@ -73,6 +74,10 @@ func (p *pod) AddServiceID(id string) { p.serviceIDs = append(p.serviceIDs, id) } +func (p *pod) State() string { + return string(p.Status.Phase) +} + func (p *pod) GetNode() report.Node { n := report.MakeNodeWith(map[string]string{ PodID: p.ID(), @@ -80,6 +85,7 @@ func (p *pod) GetNode() report.Node { Namespace: p.Namespace(), PodCreated: p.Created(), PodContainerIDs: strings.Join(p.ContainerIDs(), " "), + PodState: p.State(), }) if len(p.serviceIDs) > 0 { n = n.WithLatests(map[string]string{ServiceIDs: strings.Join(p.serviceIDs, " ")}) diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index e7da0c28a7..ac9768da6e 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -11,8 +11,9 @@ import ( var ( PodMetadataTemplates = report.MetadataTemplates{ PodID: {ID: PodID, Label: "ID", From: report.FromLatest, Priority: 1}, - Namespace: {ID: Namespace, Label: "Namespace", From: report.FromLatest, Priority: 2}, - PodCreated: {ID: PodCreated, Label: "Created", From: report.FromLatest, Priority: 3}, + PodState: {ID: PodState, Label: "State", From: report.FromLatest, Priority: 2}, + Namespace: {ID: Namespace, Label: "Namespace", From: report.FromLatest, Priority: 3}, + PodCreated: {ID: PodCreated, Label: "Created", From: report.FromLatest, Priority: 4}, } ServiceMetadataTemplates = report.MetadataTemplates{ diff --git a/render/detailed/node_test.go b/render/detailed/node_test.go index 7e2d5ed53f..eec2c22fae 100644 --- a/render/detailed/node_test.go +++ b/render/detailed/node_test.go @@ -294,3 +294,117 @@ func TestMakeDetailedContainerNode(t *testing.T) { t.Errorf("%s", test.Diff(want, have)) } } + +func TestMakeDetailedPodNode(t *testing.T) { + id := fixture.ServerPodNodeID + renderableNodes := render.PodRenderer.Render(fixture.Report) + renderableNode, ok := renderableNodes[id] + if !ok { + t.Fatalf("Node not found: %s", id) + } + have := detailed.MakeNode("pods", fixture.Report, renderableNodes, renderableNode) + + containerNodeSummary := child(t, render.ContainerRenderer, fixture.ServerContainerNodeID) + serverProcessNodeSummary := child(t, render.ProcessRenderer, fixture.ServerProcessNodeID) + serverProcessNodeSummary.Linkable = true // Temporary workaround for: https://github.com/weaveworks/scope/issues/1295 + want := detailed.Node{ + NodeSummary: detailed.NodeSummary{ + ID: id, + Label: "pong-b", + Rank: "ping/pong-b", + Shape: "heptagon", + Linkable: true, + Pseudo: false, + Metadata: []report.MetadataRow{ + {ID: "kubernetes_pod_id", Label: "ID", Value: "ping/pong-b", Priority: 1}, + {ID: "kubernetes_pod_state", Label: "State", Value: "running", Priority: 2}, + {ID: "kubernetes_namespace", Label: "Namespace", Value: "ping", Priority: 3}, + }, + }, + Controls: []detailed.ControlInstance{}, + Children: []detailed.NodeSummaryGroup{ + { + Label: "Containers", + TopologyID: "containers", + Columns: []detailed.Column{ + {ID: docker.CPUTotalUsage, Label: "CPU"}, + {ID: docker.MemoryUsage, Label: "Memory"}, + }, + Nodes: []detailed.NodeSummary{containerNodeSummary}, + }, + { + Label: "Processes", + TopologyID: "processes", + Columns: []detailed.Column{ + {ID: process.PID, Label: "PID"}, + {ID: process.CPUUsage, Label: "CPU"}, + {ID: process.MemoryUsage, Label: "Memory"}, + }, + Nodes: []detailed.NodeSummary{serverProcessNodeSummary}, + }, + }, + Parents: []detailed.Parent{ + { + ID: fixture.ServerHostNodeID, + Label: fixture.ServerHostName, + TopologyID: "hosts", + }, + }, + Connections: []detailed.ConnectionsSummary{ + { + ID: "incoming-connections", + TopologyID: "pods", + Label: "Inbound", + Columns: detailed.NormalColumns, + Connections: []detailed.Connection{ + { + ID: fmt.Sprintf("%s:%s-%s:%s-%d", render.IncomingInternetID, "", fixture.ServerPodNodeID, "", 80), + NodeID: render.IncomingInternetID, + Label: render.InboundMajor, + Linkable: true, + Metadata: []report.MetadataRow{ + { + ID: "port", + Value: "80", + Datatype: "number", + }, + { + ID: "count", + Value: "1", + Datatype: "number", + }, + }, + }, + { + ID: fmt.Sprintf("%s:%s-%s:%s-%d", fixture.ClientPodNodeID, "", fixture.ServerPodNodeID, "", 80), + NodeID: fixture.ClientPodNodeID, + Label: "pong-a", + Linkable: true, + Metadata: []report.MetadataRow{ + { + ID: "port", + Value: "80", + Datatype: "number", + }, + { + ID: "count", + Value: "2", + Datatype: "number", + }, + }, + }, + }, + }, + { + ID: "outgoing-connections", + TopologyID: "pods", + Label: "Outbound", + Columns: detailed.NormalColumns, + Connections: []detailed.Connection{}, + }, + }, + } + if !reflect.DeepEqual(want, have) { + t.Errorf("%s", test.Diff(want, have)) + } +} diff --git a/test/fixture/report_fixture.go b/test/fixture/report_fixture.go index 8faf9a147d..8fa074dfda 100644 --- a/test/fixture/report_fixture.go +++ b/test/fixture/report_fixture.go @@ -355,6 +355,7 @@ var ( kubernetes.PodID: ServerPodID, kubernetes.PodName: "pong-b", kubernetes.Namespace: KubernetesNamespace, + kubernetes.PodState: "running", kubernetes.PodContainerIDs: ServerContainerID, kubernetes.ServiceIDs: ServiceID, }).WithID(ServerPodNodeID).WithTopology(report.Pod).WithParents(report.EmptySets.