Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show container ports of network namespace #2331

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/podman/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
7 changes: 6 additions & 1 deletion cmd/podman/shared/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down