-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
new flag --listen-apiserver-port for docker/podman: allow user to specify host port for api-server #11070
new flag --listen-apiserver-port for docker/podman: allow user to specify host port for api-server #11070
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -502,8 +502,13 @@ func generatePortMappings(portMappings ...PortMapping) []string { | |
result := make([]string, 0, len(portMappings)) | ||
for _, pm := range portMappings { | ||
// let docker pick a host port by leaving it as :: | ||
// example --publish=127.0.0.17::8443 will get a random host port for 8443 | ||
publish := fmt.Sprintf("--publish=%s::%d", pm.ListenAddress, pm.ContainerPort) | ||
// example --publish=127.0.0.17:8443:8443 will get a fixed host port for 8443 | ||
publish := "" | ||
if pm.HostPort != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about add a Check here to verify this port is Free and Usable and if it is not Free and usable return an error to the user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's OK. |
||
publish = fmt.Sprintf("--publish=%s:%d:%d", pm.ListenAddress, pm.HostPort, pm.ContainerPort) | ||
} else { | ||
publish = fmt.Sprintf("--publish=%s::%d", pm.ListenAddress, pm.ContainerPort) | ||
} | ||
result = append(result, publish) | ||
} | ||
return result | ||
|
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 defer needs to happen before Exit
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.
Hi @medyagh
Thanks so much for your time.
If it goes into
exit.Message
, that means the socket wouldn't be created. Do we still need to modify this snippet?You're far more familiar to Golang that me. I referred the logic in this file, example_test.go, at line 23.
Besides, I noticed #9404 has achieved this feature. The only drawback is that #9404 exposes one more random port.
Should we still work on this feature,
--listen-apiserver-port
?Please let me know what you think.
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.
@zhan9san You are correct about
defer
, if an error is returned no action is required on the socket.