-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Modify util.GetAvailablePort to produce less confusing port allocations #5591
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5591 +/- ##
==========================================
+ Coverage 70.63% 70.67% +0.03%
==========================================
Files 411 408 -3
Lines 15777 15580 -197
==========================================
- Hits 11144 11011 -133
+ Misses 3812 3758 -54
+ Partials 821 811 -10
Continue to review full report at Codecov.
|
pkg/skaffold/util/port_test.go
Outdated
|
||
func TestSystemPorts(t *testing.T) { | ||
ps := PortSet{} | ||
ps.lock.Lock() // cause deadlock: getPortIfAvailable should never check the PortSet |
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.
not sure why this is required. There's already an error if getPortIfAvailable
returns true. Also if I deliberately introduce a bug then this deadlock causes the test to hang till timeout.
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.
This is a whitebox test that verifies that Skaffold should never check the set-ports-list for system ports. The intent is that if this test hangs (e.g., someone violated this invariant), someone will quickly discover that this invariant has been violated.
Let me update this comment to be more clear.
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.
but won't that get tested anyway in t.Errorf(...)
? Also can't ps
just be nil
and you get the same thing?
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 really do want to explicitly verify that GetPortIfAvailable()
never considers ports 1–1023 separately from the provided PortSet
. The PortSet
uses locks to protect the data structure, and there's no reason to check it for this port range.
pkg/skaffold/util/port.go
Outdated
for i := 0; i < 10; i++ { | ||
port++ | ||
if getPortIfAvailable(address, port, usedPorts) { | ||
if getPortIfAvailable(port, usedPorts) { |
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.
Shd we skip iterating over next 10 ports if port number is less than 1022?
Need to revisit this as it can be necessary to map to ports 80 or 443 to enable testing of OAuth. I think the way forward here is to allow explicit user-defined port-forwards to specific ports. |
Verified that explicit local ports on user-define ports in --- examples/microservices/skaffold.yaml
+++ examples/microservices/skaffold.yaml
@@ -23,7 +23,7 @@ portForward:
- resourceType: deployment
resourceName: leeroy-web
port: 8080
- localPort: 9000
+ localPort: 80
- resourceType: deployment
resourceName: leeroy-app
port: http And the result:
But it would be nice if service ports did map to corresponding local ports if they were available:
|
// | ||
// See https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt | ||
func GetAvailablePort(port int, usedPorts *PortSet) int { | ||
if port > 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.
Sorry if this is a dumb question: Where are we preventing trying to allocate 1-1023?
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.
See #5554 (comment) for the motivation. We had another group ask as they wanted to control which service is bound to port 443 for https.
Closing this: the system ports was an unnecessary diversion |
Fixes: #5590
Related: #5554 (comment)
Description
This PR modifies our
GetAvailablePort()
function (and related functions) to:User facing changes (remove if N/A)