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

expose port range #173

Merged
merged 1 commit into from
Apr 26, 2021
Merged

Conversation

fahedouch
Copy link
Member

@fahedouch fahedouch commented Apr 14, 2021

Refacto portutil && fixing #163
Signed-off-by: fahed dorgaa fahed.dorgaa@gmail.com

@AkihiroSuda AkihiroSuda marked this pull request as draft April 15, 2021 04:35
@fahedouch fahedouch marked this pull request as ready for review April 15, 2021 14:24
@fahedouch fahedouch changed the title [WIP] expose port range expose port range Apr 15, 2021
@fahedouch fahedouch force-pushed the fix-port-range branch 2 times, most recently from 36c4472 to 8d6648f Compare April 15, 2021 14:50
}

return multi_res, nil
Copy link
Member

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


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)
Copy link
Member

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",
},
Copy link
Member

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

Copy link
Member Author

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) {
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

ip, hostPort, containerPort := splitParts(splitBySlash[0])

if containerPort == "" {
return nil, errors.Errorf("No port specified: %s<empty>", splitBySlash[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does <empty> mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing

@AkihiroSuda AkihiroSuda marked this pull request as draft April 19, 2021 14:46
@fahedouch fahedouch force-pushed the fix-port-range branch 2 times, most recently from 3a19562 to 0624f8f Compare April 19, 2021 14:57
@fahedouch fahedouch marked this pull request as ready for review April 19, 2021 14:58
run_network_test.go Outdated Show resolved Hide resolved
run_network_test.go Outdated Show resolved Hide resolved
@fahedouch fahedouch force-pushed the fix-port-range branch 2 times, most recently from d2dd140 to 5806333 Compare April 22, 2021 18:57
@fahedouch
Copy link
Member Author

@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>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants