summaryrefslogtreecommitdiff
path: root/libpod/util.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-15 04:50:40 -0400
committerGitHub <noreply@github.com>2020-07-15 04:50:40 -0400
commit6224f3f5d5f651a5bbfdc15407288d08d7af33ea (patch)
tree56476ca94445886e46f55f574fb5ad4e752ab95b /libpod/util.go
parentc4843d4e9ce395f1bbcaae848e6172f5a4519a35 (diff)
parentfbc1167c4d7861013001d0c2460c6e1c1e1ad66d (diff)
downloadpodman-6224f3f5d5f651a5bbfdc15407288d08d7af33ea.tar.gz
podman-6224f3f5d5f651a5bbfdc15407288d08d7af33ea.tar.bz2
podman-6224f3f5d5f651a5bbfdc15407288d08d7af33ea.zip
Merge pull request #6956 from mheon/add_ports_to_pod_inspect
Include infra container information in `pod inspect`
Diffstat (limited to 'libpod/util.go')
-rw-r--r--libpod/util.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/libpod/util.go b/libpod/util.go
index 7504295f0..8c2d946ba 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -15,6 +15,7 @@ import (
"github.com/containers/common/pkg/config"
"github.com/containers/libpod/v2/libpod/define"
"github.com/containers/libpod/v2/utils"
+ "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/fsnotify/fsnotify"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
@@ -254,3 +255,21 @@ func makeHTTPAttachHeader(stream byte, length uint32) []byte {
binary.BigEndian.PutUint32(header[4:], length)
return header
}
+
+// Convert OCICNI port bindings into Inspect-formatted port bindings.
+func makeInspectPortBindings(bindings []ocicni.PortMapping) map[string][]define.InspectHostPort {
+ portBindings := make(map[string][]define.InspectHostPort)
+ for _, port := range bindings {
+ key := fmt.Sprintf("%d/%s", port.ContainerPort, port.Protocol)
+ hostPorts := portBindings[key]
+ if hostPorts == nil {
+ hostPorts = []define.InspectHostPort{}
+ }
+ hostPorts = append(hostPorts, define.InspectHostPort{
+ HostIP: port.HostIP,
+ HostPort: fmt.Sprintf("%d", port.HostPort),
+ })
+ portBindings[key] = hostPorts
+ }
+ return portBindings
+}