Merge pull request #1578 from weaveworks/1573-multi-network-containers

Gather IPs from all the container networks
This commit is contained in:
Alfonso Acosta
2016-06-13 13:23:06 +01:00
committed by GitHub
3 changed files with 20 additions and 9 deletions

View File

@@ -311,18 +311,21 @@ func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets {
c.RLock()
defer c.RUnlock()
ips := c.container.NetworkSettings.SecondaryIPAddresses
if c.container.NetworkSettings.IPAddress != "" {
ips = append(ips, c.container.NetworkSettings.IPAddress)
}
// For now, for the proof-of-concept, we just add networks as a set of
// names. For the next iteration, we will probably want to create a new
// Network topology, populate the network nodes with all of the details
// here, and provide foreign key links from nodes to networks.
networks := make([]string, 0, len(c.container.NetworkSettings.Networks))
for name := range c.container.NetworkSettings.Networks {
for name, settings := range c.container.NetworkSettings.Networks {
networks = append(networks, name)
}
ips := c.container.NetworkSettings.SecondaryIPAddresses
if c.container.NetworkSettings.IPAddress != "" {
ips = append(ips, c.container.NetworkSettings.IPAddress)
if settings.IPAddress != "" {
ips = append(ips, settings.IPAddress)
}
}
// Treat all Docker IPs as local scoped.

View File

@@ -114,7 +114,10 @@ func TestContainer(t *testing.T) {
Add("docker_container_ports", report.MakeStringSet("1.2.3.4:80->80/tcp", "81/tcp")).
Add("docker_container_networks", nil).
Add("docker_container_ips", report.MakeStringSet("1.2.3.4")).
Add("docker_container_ips_with_scopes", report.MakeStringSet(";1.2.3.4"))
Add("docker_container_ips", report.MakeStringSet("5.6.7.8")).
Add("docker_container_ips_with_scopes", report.MakeStringSet(";1.2.3.4")).
Add("docker_container_ips_with_scopes", report.MakeStringSet(";5.6.7.8")).
Add("docker_container_networks", report.MakeStringSet("network1"))
test.Poll(t, 100*time.Millisecond, want, func() interface{} {
return c.NetworkInfo([]net.IP{})
@@ -128,7 +131,7 @@ func TestContainer(t *testing.T) {
t.Errorf("%d != 2", c.PID())
}
node := c.GetNode().WithSets(c.NetworkInfo([]net.IP{}))
if have := docker.ExtractContainerIPs(node); !reflect.DeepEqual(have, []string{"1.2.3.4"}) {
t.Errorf("%v != %v", have, []string{"1.2.3.4"})
if have := docker.ExtractContainerIPs(node); !reflect.DeepEqual(have, []string{"1.2.3.4", "5.6.7.8"}) {
t.Errorf("%v != %v", have, []string{"1.2.3.4", "5.6.7.8"})
}
}

View File

@@ -196,6 +196,11 @@ var (
},
client.Port("81/tcp"): {},
},
Networks: map[string]client.ContainerNetwork{
"network1": {
IPAddress: "5.6.7.8",
},
},
},
Config: &client.Config{
Labels: map[string]string{