-
Notifications
You must be signed in to change notification settings - Fork 604
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
expose port range #173
expose port range #173
Conversation
51cb9c3
to
541c290
Compare
36c4472
to
8d6648f
Compare
pkg/portutil/portutil.go
Outdated
} | ||
|
||
return multi_res, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underscore is discouraged in Go
pkg/portutil/portutil.go
Outdated
|
||
if hostPort != "" && (endPort-startPort) != (endHostPort-startHostPort) { | ||
if endPort != startPort { | ||
return nil, errors.Errorf("Invalid ranges specified for container and host Ports: %s and %s", containerPort, hostPort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go discourages using an error string that start with a lower character
hostPort: "7000-7005", | ||
containerPort: "80", | ||
connectURLPort: 7005, | ||
err: "connection refused", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also test an invalid range such as -p 7000-7005:79-85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"github.com/pkg/errors" | ||
) | ||
|
||
func ParseFlagP(s string) (*gocni.PortMapping, error) { | ||
func splitParts(rawport string) (string, string, string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs comment lines to explain the ret values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
case 3: | ||
return parts[0], parts[1], containerport | ||
default: | ||
return strings.Join(parts[:n-2], ":"), parts[n-2], containerport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch is hard to read. Is this default
case for IPv6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I targeting Ipv4 here
look a this two example :
./nerdctl --snapshotter native run -d -p 1515:127.0.0.1:80:80 alpine sleep 100
parts = [1515 127.0.0.1 80 80]
parts[n-1] -> 80
parts[n-2] -> 80
parts[:n-2] -> [ 1515 127.0.0.1] So strings.Join(parts[:n-2], ":") => 1515:127.0.0.1 (original input)
./nerdctl --snapshotter native run -d -p 1515-127.0.0.1:80:80 alpine sleep 100
parts = [1515-127.0.0.1 80 80]
parts[n-1] -> 80
parts[n-2] -> 80
parts[:n-2] -> [1515-127.0.0.1] So strings.Join(parts[:n-2], ":") => 1515-127.0.0.1
it is ok for ipv6 too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what 1515-127.0.0.1:80:80
means. Is it officially supported by Docker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AkihiroSuda it is a wrong IP that a user may try (just an example)
the purpose is to get the IP block and check it.
pkg/portutil/portutil.go
Outdated
ip, hostPort, containerPort := splitParts(splitBySlash[0]) | ||
|
||
if containerPort == "" { | ||
return nil, errors.Errorf("No port specified: %s<empty>", splitBySlash[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does <empty>
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing
3a19562
to
0624f8f
Compare
d2dd140
to
5806333
Compare
@AkihiroSuda can you re-review plz. |
Signed-off-by: fahed dorgaa <fahed.dorgaa@gmail.com> fix tests Signed-off-by: fahed dorgaa <fahed.dorgaa@gmail.com>
8edbc32
to
459eba6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Refacto
portutil
&& fixing #163Signed-off-by: fahed dorgaa fahed.dorgaa@gmail.com