mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
Review Feedback
This commit is contained in:
@@ -137,35 +137,28 @@ func (r containerWithHostIPsRenderer) Render(rpt report.Report) RenderableNodes
|
||||
continue
|
||||
}
|
||||
|
||||
ips, ok := c.Node.Sets.Lookup(docker.ContainerIPs)
|
||||
if ok && len(ips) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
h, ok := hosts[MakeHostID(report.ExtractHostID(c.Node))]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
hostNetworks, ok := h.Sets.Lookup(host.LocalNetworks)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
hostIPs := report.MakeStringSet()
|
||||
newIPs := report.MakeStringSet()
|
||||
hostNetworks, _ := h.Sets.Lookup(host.LocalNetworks)
|
||||
for _, cidr := range hostNetworks {
|
||||
if ip, _, err := net.ParseCIDR(cidr); err == nil {
|
||||
hostIPs = hostIPs.Add(ip.String())
|
||||
newIPs = newIPs.Add(ip.String())
|
||||
}
|
||||
}
|
||||
|
||||
c.Sets = c.Sets.Add(docker.ContainerIPs, hostIPs)
|
||||
c.Sets = c.Sets.Add(docker.ContainerIPs, newIPs)
|
||||
containers[id] = c
|
||||
}
|
||||
|
||||
return containers
|
||||
}
|
||||
|
||||
// ContainerWithHostIPsRenderer is a Renderer which produces a container graph
|
||||
// enriched with host IPs on containers where NetworkMode is Host
|
||||
var ContainerWithHostIPsRenderer = containerWithHostIPsRenderer{ContainerRenderer}
|
||||
|
||||
type containerWithImageNameRenderer struct {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/weaveworks/scope/probe/kubernetes"
|
||||
"github.com/weaveworks/scope/render"
|
||||
"github.com/weaveworks/scope/render/expected"
|
||||
"github.com/weaveworks/scope/report"
|
||||
"github.com/weaveworks/scope/test"
|
||||
"github.com/weaveworks/scope/test/fixture"
|
||||
)
|
||||
@@ -51,6 +52,25 @@ func TestContainerFilterRenderer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainerWithHostIPsRenderer(t *testing.T) {
|
||||
input := fixture.Report.Copy()
|
||||
input.Container.Nodes[fixture.ClientContainerNodeID] = input.Container.Nodes[fixture.ClientContainerNodeID].WithLatests(map[string]string{
|
||||
docker.ContainerNetworkMode: "host",
|
||||
})
|
||||
nodes := render.ContainerWithHostIPsRenderer.Render(input)
|
||||
|
||||
// Test host network nodes get the host IPs added.
|
||||
haveNode, ok := nodes[render.MakeContainerID(fixture.ClientContainerID)]
|
||||
if !ok {
|
||||
t.Fatal("Expected output to have the client container node")
|
||||
}
|
||||
have, _ := haveNode.Sets.Lookup(docker.ContainerIPs)
|
||||
want := report.MakeStringSet("10.10.10.0")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Error(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainerFilterRendererImageName(t *testing.T) {
|
||||
// Test nodes are filtered by image name as well.
|
||||
input := fixture.Report.Copy()
|
||||
|
||||
Reference in New Issue
Block a user