Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2755 from allencloud/fix-panic-in-UpdateNetworkCo…
Browse files Browse the repository at this point in the history
…ntainers

fix panic in UpdateNetworkContainers
  • Loading branch information
nishanttotla authored Jul 5, 2017
2 parents 2005aec + cd185d9 commit 326f750
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions cluster/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,38 +996,42 @@ func (e *Engine) UpdateNetworkContainers(containerID string, full bool) error {
continue
}
for _, n := range c.NetworkSettings.Networks {
if engineNetwork, ok := e.networks[n.NetworkID]; ok {
// extract container name
ctrName := ""
if len(c.Names) != 0 {
if s := strings.Split(c.Names[0], "/"); len(s) > 1 {
ctrName = s[1]
} else {
ctrName = s[0]
}
}
// extract ip addresses
ipv4address := ""
ipv6address := ""
if n.IPAddress != "" {
ipv4address = n.IPAddress + "/" + strconv.Itoa(n.IPPrefixLen)
}
if n.GlobalIPv6Address != "" {
ipv6address = n.GlobalIPv6Address + "/" + strconv.Itoa(n.GlobalIPv6PrefixLen)
}
// udpate network information
engineNetwork.Containers[c.ID] = types.EndpointResource{
Name: ctrName,
EndpointID: n.EndpointID,
MacAddress: n.MacAddress,
IPv4Address: ipv4address,
IPv6Address: ipv6address,
}
} else {
engineNetwork, ok := e.networks[n.NetworkID]
if !ok {
// it shouldn't be the case that a network which a container is connected to wasn't
// even listed. Return an error when that happens.
return fmt.Errorf("container %s connected to network %s but the network wasn't listed in the refresh loop", c.ID, n.NetworkID)
}

// extract container name
ctrName := ""
if len(c.Names) != 0 {
if s := strings.Split(c.Names[0], "/"); len(s) > 1 {
ctrName = s[1]
} else {
ctrName = s[0]
}
}
// extract ip addresses
ipv4address := ""
ipv6address := ""
if n.IPAddress != "" {
ipv4address = n.IPAddress + "/" + strconv.Itoa(n.IPPrefixLen)
}
if n.GlobalIPv6Address != "" {
ipv6address = n.GlobalIPv6Address + "/" + strconv.Itoa(n.GlobalIPv6PrefixLen)
}
// update network information
if engineNetwork.Containers == nil {
engineNetwork.Containers = make(map[string]types.EndpointResource)
}
engineNetwork.Containers[c.ID] = types.EndpointResource{
Name: ctrName,
EndpointID: n.EndpointID,
MacAddress: n.MacAddress,
IPv4Address: ipv4address,
IPv6Address: ipv6address,
}
}
}
return nil
Expand Down

0 comments on commit 326f750

Please sign in to comment.