Check container is running before trying to open its namespace

Otherwise we get pointless errors.
This commit is contained in:
Bryan Boreham
2018-07-23 21:37:22 +00:00
parent fbe4cd2af9
commit 53c406f7e0

View File

@@ -277,15 +277,17 @@ func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets {
ips = append(ips, c.container.NetworkSettings.IPAddress)
}
// Fetch IP addresses from the container's namespace
cidrs, err := namespaceIPAddresses(c.container.State.Pid)
if err != nil {
log.Debugf("container %s: failed to get addresses: %s", c.container.ID, err)
}
for _, cidr := range cidrs {
// This address can duplicate an address fetched from Docker earlier,
// but we eventually turn the lists into sets which will remove duplicates.
ips = append(ips, cidr.IP.String())
if c.container.State.Running && c.container.State.Pid != 0 {
// Fetch IP addresses from the container's namespace
cidrs, err := namespaceIPAddresses(c.container.State.Pid)
if err != nil {
log.Debugf("container %s: failed to get addresses: %s", c.container.ID, err)
}
for _, cidr := range cidrs {
// This address can duplicate an address fetched from Docker earlier,
// but we eventually turn the lists into sets which will remove duplicates.
ips = append(ips, cidr.IP.String())
}
}
// For now, for the proof-of-concept, we just add networks as a set of