summaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-12-08 19:05:25 -0500
committerGitHub <noreply@github.com>2020-12-08 19:05:25 -0500
commitdd295f297b6dd51d22c64c75f4ef4f80f953bbde (patch)
treee207fa339c7dcbd4f6c9f31ac0663bcebe41ecdb /pkg/specgen
parent7caef9c497da0c2a16caf4f15152bc543dfb6008 (diff)
parent6b7612062ebf25f9969233b1accea3e376c313cc (diff)
downloadpodman-dd295f297b6dd51d22c64c75f4ef4f80f953bbde.tar.gz
podman-dd295f297b6dd51d22c64c75f4ef4f80f953bbde.tar.bz2
podman-dd295f297b6dd51d22c64c75f4ef4f80f953bbde.zip
Merge pull request #8652 from mheon/fix_8650
Correct port range logic for port generation
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/generate/ports.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go
index 5c13c95b2..83ded059f 100644
--- a/pkg/specgen/generate/ports.go
+++ b/pkg/specgen/generate/ports.go
@@ -107,7 +107,11 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
var index uint16
for index = 0; index < len; index++ {
cPort := containerPort + index
- hPort := hostPort + index
+ hPort := hostPort
+ // Only increment host port if it's not 0.
+ if hostPort != 0 {
+ hPort += index
+ }
if cPort == 0 {
return nil, nil, nil, errors.Errorf("container port cannot be 0")
@@ -162,8 +166,8 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
tempMappings,
tempMapping{
mapping: cniPort,
- startOfRange: port.Range > 0 && index == 0,
- isInRange: port.Range > 0,
+ startOfRange: port.Range > 1 && index == 0,
+ isInRange: port.Range > 1,
},
)
}
@@ -183,7 +187,7 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
for _, tmp := range tempMappings {
p := tmp.mapping
- if p.HostPort != 0 && !tmp.isInRange {
+ if p.HostPort != 0 {
remadeMappings = append(remadeMappings, p)
continue
}