Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show k8s pod status #1289

Merged
merged 2 commits into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions probe/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -73,13 +74,18 @@ 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(),
PodName: p.Name(),
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, " ")})
Expand Down
5 changes: 3 additions & 2 deletions probe/kubernetes/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
114 changes: 114 additions & 0 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
1 change: 1 addition & 0 deletions test/fixture/report_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down