diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-21 18:45:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 18:45:07 +0100 |
commit | 2f6cdd353f50e6c26b34f0b1bff028e8393d2580 (patch) | |
tree | 473c73e16b14752f3c205d4182400a51b902f128 /pkg/specgen | |
parent | a6976c9ca8346331001dfade295173ad1482c2f6 (diff) | |
parent | d173ebc067e912a1f0d272fab19fa0b3db4d4c05 (diff) | |
download | podman-2f6cdd353f50e6c26b34f0b1bff028e8393d2580.tar.gz podman-2f6cdd353f50e6c26b34f0b1bff028e8393d2580.tar.bz2 podman-2f6cdd353f50e6c26b34f0b1bff028e8393d2580.zip |
Merge pull request #12305 from colinbendell/add-expose-port-range
Support EXPOSE with port ranges
Diffstat (limited to 'pkg/specgen')
-rw-r--r-- | pkg/specgen/generate/ports.go | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go index 53a5e5697..b60cc1e98 100644 --- a/pkg/specgen/generate/ports.go +++ b/pkg/specgen/generate/ports.go @@ -5,7 +5,6 @@ import ( "fmt" "net" "sort" - "strconv" "strings" "github.com/containers/common/libimage" @@ -13,6 +12,7 @@ import ( "github.com/containers/podman/v3/utils" "github.com/containers/podman/v3/pkg/specgen" + "github.com/containers/podman/v3/pkg/specgenutil" "github.com/containers/podman/v3/pkg/util" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -410,31 +410,13 @@ func checkProtocol(protocol string, allowSCTP bool) ([]string, error) { } func GenExposedPorts(exposedPorts map[string]struct{}) (map[uint16]string, error) { - expose := make(map[uint16]string, len(exposedPorts)) - for imgExpose := range exposedPorts { - // Expose format is portNumber[/protocol] - splitExpose := strings.SplitN(imgExpose, "/", 2) - num, err := strconv.Atoi(splitExpose[0]) - if err != nil { - return nil, errors.Wrapf(err, "unable to convert image EXPOSE statement %q to port number", imgExpose) - } - if num > 65535 || num < 1 { - return nil, errors.Errorf("%d from image EXPOSE statement %q is not a valid port number", num, imgExpose) - } - - // No need to validate protocol, we'll do it later. - newProto := "tcp" - if len(splitExpose) == 2 { - newProto = splitExpose[1] - } - - proto := expose[uint16(num)] - if len(proto) > 1 { - proto = proto + "," + newProto - } else { - proto = newProto - } - expose[uint16(num)] = proto + expose := make([]string, 0, len(exposedPorts)) + for e := range exposedPorts { + expose = append(expose, e) + } + toReturn, err := specgenutil.CreateExpose(expose) + if err != nil { + return nil, errors.Wrapf(err, "unable to convert image EXPOSE") } - return expose, nil + return toReturn, nil } |