Review Feedback

This commit is contained in:
Paul Bellamy
2016-02-19 11:07:00 +00:00
parent df856d78dc
commit 5535f5e738
3 changed files with 31 additions and 14 deletions

View File

@@ -355,10 +355,14 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
result = result.WithControls(UnpauseContainer)
} else if c.container.State.Running {
uptime := (mtime.Now().Sub(c.container.State.StartedAt) / time.Second) * time.Second
networkMode := ""
if c.container.HostConfig != nil {
networkMode = c.container.HostConfig.NetworkMode
}
result = result.WithLatests(map[string]string{
ContainerUptime: uptime.String(),
ContainerRestartCount: strconv.Itoa(c.container.RestartCount),
ContainerNetworkMode: c.container.HostConfig.NetworkMode,
ContainerNetworkMode: networkMode,
})
result = result.WithControls(
RestartContainer, StopContainer, PauseContainer, AttachContainer, ExecContainer,

View File

@@ -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 {

View File

@@ -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()