summaryrefslogtreecommitdiff
path: root/libpod/container_internal.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r--libpod/container_internal.go79
1 files changed, 10 insertions, 69 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 1033729ae..9ac2cd5bd 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -644,17 +644,8 @@ func (c *Container) refresh() error {
}
c.lock = lock
- // Try to delete any lingering IP allocations.
- // If this fails, just log and ignore.
- // I'm a little concerned that this is so far down in refresh() and we
- // could fail before getting to it - but the worst that would happen is
- // that Inspect() would return info on IPs we no longer own.
- if len(c.state.NetworkStatus) > 0 {
- if err := c.removeIPv4Allocations(); err != nil {
- logrus.Errorf("Error removing IP allocations for container %s: %v", c.ID(), err)
- }
- }
c.state.NetworkStatus = nil
+ c.state.NetworkStatusOld = nil
if err := c.save(); err != nil {
return errors.Wrapf(err, "error refreshing state for container %s", c.ID())
@@ -668,57 +659,6 @@ func (c *Container) refresh() error {
return nil
}
-// Try and remove IP address allocations. Presently IPv4 only.
-// Should be safe as rootless because NetworkStatus should only be populated if
-// CNI is running.
-func (c *Container) removeIPv4Allocations() error {
- cniNetworksDir, err := getCNINetworksDir()
- if err != nil {
- return err
- }
-
- if len(c.state.NetworkStatus) == 0 {
- return nil
- }
-
- cniDefaultNetwork := ""
- if c.runtime.netPlugin != nil {
- cniDefaultNetwork = c.runtime.netPlugin.GetDefaultNetworkName()
- }
-
- networks, _, err := c.networks()
- if err != nil {
- return err
- }
-
- if len(networks) != len(c.state.NetworkStatus) {
- return errors.Wrapf(define.ErrInternal, "network mismatch: asked to join %d CNI networks but got %d CNI results", len(networks), len(c.state.NetworkStatus))
- }
-
- for index, result := range c.state.NetworkStatus {
- for _, ctrIP := range result.IPs {
- if ctrIP.Version != "4" {
- continue
- }
- candidate := ""
- if len(networks) > 0 {
- // CNI returns networks in order we passed them.
- // So our index into results should be our index
- // into networks.
- candidate = filepath.Join(cniNetworksDir, networks[index], ctrIP.Address.IP.String())
- } else {
- candidate = filepath.Join(cniNetworksDir, cniDefaultNetwork, ctrIP.Address.IP.String())
- }
- logrus.Debugf("Going to try removing IP address reservation file %q for container %s", candidate, c.ID())
- if err := os.Remove(candidate); err != nil && !os.IsNotExist(err) {
- return errors.Wrapf(err, "error removing CNI IP reservation file %q for container %s", candidate, c.ID())
- }
- }
- }
-
- return nil
-}
-
// Remove conmon attach socket and terminal resize FIFO
// This is necessary for restarting containers
func (c *Container) removeConmonFiles() error {
@@ -1017,11 +957,9 @@ func (c *Container) completeNetworkSetup() error {
}
state := c.state
// collect any dns servers that cni tells us to use (dnsname)
- for _, cni := range state.NetworkStatus {
- if cni.DNS.Nameservers != nil {
- for _, server := range cni.DNS.Nameservers {
- outResolvConf = append(outResolvConf, fmt.Sprintf("nameserver %s", server))
- }
+ for _, status := range c.getNetworkStatus() {
+ for _, server := range status.DNSServerIPs {
+ outResolvConf = append(outResolvConf, fmt.Sprintf("nameserver %s", server))
}
}
// check if we have a bindmount for /etc/hosts
@@ -1062,9 +1000,12 @@ func (c *Container) completeNetworkSetup() error {
func (c *Container) cniHosts() string {
var hosts string
- if len(c.state.NetworkStatus) > 0 && len(c.state.NetworkStatus[0].IPs) > 0 {
- ipAddress := strings.Split(c.state.NetworkStatus[0].IPs[0].Address.String(), "/")[0]
- hosts += fmt.Sprintf("%s\t%s %s\n", ipAddress, c.Hostname(), c.Config().Name)
+ for _, status := range c.getNetworkStatus() {
+ for _, netInt := range status.Interfaces {
+ for _, netAddress := range netInt.Networks {
+ hosts += fmt.Sprintf("%s\t%s %s\n", netAddress.Subnet.IP.String(), c.Hostname(), c.Config().Name)
+ }
+ }
}
return hosts
}