Follow-up to 494677f93f, which added
the aliases, but did not yet replace our own use of the nat types.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.
Remove these imports in preparation of migrating our code to become an
actual go module.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Rewrite the range-detection logic to prevent duplicate env-vars,
and to avoid looping over the same values multiple times.
Benchmark before / after:
goos: darwin
goarch: arm64
pkg: github.com/docker/docker/daemon/links
cpu: Apple M1 Pro
BenchmarkLinkMultipleEnv
BenchmarkLinkMultipleEnvOld-10 92817 12072 ns/op 8516 B/op 316 allocs/op
BenchmarkLinkMultipleEnvNew-10 149493 7792 ns/op 6435 B/op 213 allocs/op
PASS
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The code incorrectly created env-vars for consecutive port numbers with
a different protocol; we should only consider ports to be part of a range
if they have consecutive port-numbers and have the same protocol.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The intent of this sorting was twofold;
- the "default" port of the container to be the first TCP port (if present)
- consecutive port-mappings with the same protocol to be together so
that port-ranges would produce an env-var describing the range.
The current sorting would sort TCP ports before UDP (or SCTP) port, but
only if they had the same port-number. This could result in range-detection
incorrectly combining TCP and UDP (or SCTP) ports in the same range.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
There's no need to loop and sort multiple times; this code picked
the first port after sorting, which we already did in this function.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.
TestLinkPortRangeEnv was added in 611a23aa7f
to test for port-ranges to produce the expected env-vars, but used the
same input as TestLinkMultipleEnv. Now that we assert all env-vars produced,
it became a duplicate of TestLinkMultipleEnv, so we can remove that test.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Simplify the test by testing the result, instead of manually checking
specific values. This makes sure we check the actual results, and don't
miss values, or ignore unexpected values.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This utility was added in 12b6083c8f as a
replacement for nat.NewPort(), which before that patch would panic on
invalid values, but was changed to return an error.
Given that the utility ignores any error, and these values are fixed values
for the test, let's remove it to simplify constructing the tests.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
strings.ReplaceAll(s, old, new) is a wrapper function for
strings.Replace(s, old, new, -1). But strings.ReplaceAll is more
readable and removes the hardcoded -1.
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>