mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
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>
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user