summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-13 13:22:58 -0600
committerbaude <bbaude@redhat.com>2019-02-13 13:51:23 -0600
commitdd74467fd8dcbdab35b4c7fc2dc183d12fb228f2 (patch)
tree647d88b335a6da3e6fbdf481694223fd9b7c8026
parent8a16f83b0a13ab9de1cc905a3ff1132c75739995 (diff)
downloadpodman-dd74467fd8dcbdab35b4c7fc2dc183d12fb228f2.tar.gz
podman-dd74467fd8dcbdab35b4c7fc2dc183d12fb228f2.tar.bz2
podman-dd74467fd8dcbdab35b4c7fc2dc183d12fb228f2.zip
show container ports of network namespace
in cases where a container is part of a network namespace, we should show the network namespace's ports when dealing with ports. this impacts ps, kube, and port. fixes: #846 Signed-off-by: baude <bbaude@redhat.com>
-rw-r--r--cmd/podman/port.go7
-rw-r--r--cmd/podman/shared/container.go7
-rw-r--r--libpod/container.go12
-rw-r--r--libpod/kube.go6
4 files changed, 27 insertions, 5 deletions
diff --git a/cmd/podman/port.go b/cmd/podman/port.go
index 5a5b6127b..be84da065 100644
--- a/cmd/podman/port.go
+++ b/cmd/podman/port.go
@@ -125,8 +125,13 @@ func portCmd(c *cliconfig.PortValues) error {
if c.All {
fmt.Println(con.ID())
}
+
+ portmappings, err := con.PortMappings()
+ if err != nil {
+ return err
+ }
// Iterate mappings
- for _, v := range con.Config().PortMappings {
+ for _, v := range portmappings {
hostIP := v.HostIP
// Set host IP to 0.0.0.0 if blank
if hostIP == "" {
diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go
index c74d8fdce..81811e0f2 100644
--- a/cmd/podman/shared/container.go
+++ b/cmd/podman/shared/container.go
@@ -213,11 +213,16 @@ func NewBatchContainer(ctr *libpod.Container, opts PsOptions) (PsContainerOutput
}
}
+ ports, err := ctr.PortMappings()
+ if err != nil {
+ logrus.Errorf("unable to lookup namespace container for %s", ctr.ID())
+ }
+
pso.ID = cid
pso.Image = imageName
pso.Command = command
pso.Created = created
- pso.Ports = portsToString(ctr.PortMappings())
+ pso.Ports = portsToString(ports)
pso.Names = ctr.Name()
pso.IsInfra = ctr.IsInfra()
pso.Status = status
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
}