From 6db171bc9be258128649e4e9883b42cb89dbac62 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 19 Apr 2016 17:49:06 +0100 Subject: [PATCH] Add a 'Unmanaged' node to k8s views which included non-k8s containers. --- render/detailed/summary.go | 9 +++++++++ render/expected/expected.go | 11 +++++++++-- render/mapping.go | 18 ++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/render/detailed/summary.go b/render/detailed/summary.go index 4bc9c38a86..37c21a14fd 100644 --- a/render/detailed/summary.go +++ b/render/detailed/summary.go @@ -162,6 +162,15 @@ func pseudoNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) { return base, true } + // try rendering it as an unmanaged node + if strings.HasPrefix(n.ID, render.MakePseudoNodeID(render.UnmanagedID)) { + base.Label = render.UnmanagedMajor + base.Shape = Square + base.Stack = true + base.LabelMinor = report.ExtractHostID(n) + return base, true + } + // try rendering it as an endpoint if addr, ok := n.Latest.Lookup(endpoint.Addr); ok { base.Label = addr diff --git a/render/expected/expected.go b/render/expected/expected.go index 76be268110..5f70ff9a5b 100644 --- a/render/expected/expected.go +++ b/render/expected/expected.go @@ -235,6 +235,13 @@ var ( render.OutgoingInternetID: theOutgoingInternetNode, } + unmanagedServerID = render.MakePseudoNodeID(render.UnmanagedID, fixture.ServerHostID) + unmanagedServerNode = pseudo(unmanagedServerID, render.OutgoingInternetID).WithChildren(report.MakeNodeSet( + uncontainedServerNode, + RenderedEndpoints[fixture.NonContainerNodeID], + RenderedProcesses[fixture.NonContainerProcessNodeID], + )) + RenderedPods = report.Nodes{ fixture.ClientPodNodeID: pod(fixture.ClientPodNodeID, fixture.ServerPodNodeID). WithChildren(report.MakeNodeSet( @@ -252,7 +259,7 @@ var ( RenderedContainers[fixture.ServerContainerNodeID], )), - uncontainedServerID: uncontainedServerNode, + unmanagedServerID: unmanagedServerNode, render.IncomingInternetID: theIncomingInternetNode(fixture.ServerPodNodeID), render.OutgoingInternetID: theOutgoingInternetNode, } @@ -272,7 +279,7 @@ var ( RenderedPods[fixture.ServerPodNodeID], )), - uncontainedServerID: uncontainedServerNode, + unmanagedServerID: unmanagedServerNode, render.IncomingInternetID: theIncomingInternetNode(fixture.ServiceNodeID), render.OutgoingInternetID: theOutgoingInternetNode, } diff --git a/render/mapping.go b/render/mapping.go index ee8752b0d6..969c65eaf3 100644 --- a/render/mapping.go +++ b/render/mapping.go @@ -18,6 +18,9 @@ const ( UncontainedID = "uncontained" UncontainedMajor = "Uncontained" + UnmanagedID = "unmanaged" + UnmanagedMajor = "Unmanaged" + TheInternetID = "theinternet" IncomingInternetID = "in-" + TheInternetID OutgoingInternetID = "out-" + TheInternetID @@ -364,6 +367,13 @@ func MapEndpoint2Host(n report.Node, local report.Networks) report.Nodes { // It does not have enough info to do that, and the resulting graph // must be merged with a container graph to get that info. func MapContainer2Pod(n report.Node, _ report.Networks) report.Nodes { + // Uncontainerd becomes unmanaged in the pods view + if strings.HasPrefix(n.ID, MakePseudoNodeID(UncontainedID)) { + id := MakePseudoNodeID(UnmanagedID, report.ExtractHostID(n)) + node := NewDerivedPseudoNode(id, n) + return report.Nodes{id: node} + } + // Propagate all pseudo nodes if n.Topology == Pseudo { return report.Nodes{n.ID: n} @@ -373,11 +383,15 @@ func MapContainer2Pod(n report.Node, _ report.Networks) report.Nodes { // slightly out of sync reports, or its not in a pod), just drop it namespace, ok := n.Latest.Lookup(kubernetes.Namespace) if !ok { - return report.Nodes{} + id := MakePseudoNodeID(UnmanagedID, report.ExtractHostID(n)) + node := NewDerivedPseudoNode(id, n) + return report.Nodes{id: node} } podID, ok := n.Latest.Lookup(kubernetes.PodID) if !ok { - return report.Nodes{} + id := MakePseudoNodeID(UnmanagedID, report.ExtractHostID(n)) + node := NewDerivedPseudoNode(id, n) + return report.Nodes{id: node} } podName := strings.TrimPrefix(podID, namespace+"/") id := report.MakePodNodeID(namespace, podName)