diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-13 21:30:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-13 21:30:00 +0100 |
commit | e86aec78551d8f792fd6d7e1f450e16bebd14701 (patch) | |
tree | 3a3cc4ac3c95f4f5eb544caadb6643faf5c9e21f /libpod | |
parent | fa3b91dc1216e6057e24a574bec566401800d780 (diff) | |
parent | dd74467fd8dcbdab35b4c7fc2dc183d12fb228f2 (diff) | |
download | podman-e86aec78551d8f792fd6d7e1f450e16bebd14701.tar.gz podman-e86aec78551d8f792fd6d7e1f450e16bebd14701.tar.bz2 podman-e86aec78551d8f792fd6d7e1f450e16bebd14701.zip |
Merge pull request #2331 from baude/issue846
show container ports of network namespace
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 12 | ||||
-rw-r--r-- | libpod/kube.go | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/libpod/container.go b/libpod/container.go index b0589be3b..fec61533d 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -557,8 +557,16 @@ func (c *Container) NewNetNS() bool { // PortMappings returns the ports that will be mapped into a container if // a new network namespace is created // If NewNetNS() is false, this value is unused -func (c *Container) PortMappings() []ocicni.PortMapping { - return c.config.PortMappings +func (c *Container) PortMappings() ([]ocicni.PortMapping, error) { + // First check if the container belongs to a network namespace (like a pod) + if len(c.config.NetNsCtr) > 0 { + netNsCtr, err := c.runtime.LookupContainer(c.config.NetNsCtr) + if err != nil { + return nil, errors.Wrapf(err, "unable to lookup network namespace for container %s", c.ID()) + } + return netNsCtr.PortMappings() + } + return c.config.PortMappings, nil } // DNSServers returns DNS servers that will be used in the container's diff --git a/libpod/kube.go b/libpod/kube.go index 16cebf99b..484127870 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -228,7 +228,11 @@ func containerToV1Container(c *Container) (v1.Container, error) { return kubeContainer, nil } - ports, err := ocicniPortMappingToContainerPort(c.PortMappings()) + portmappings, err := c.PortMappings() + if err != nil { + return kubeContainer, err + } + ports, err := ocicniPortMappingToContainerPort(portmappings) if err != nil { return kubeContainer, nil } |