-
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 2 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.
Doesn’t this need to be defer ?
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 for pointing it out.
The code snippet above is replaced by
defer
.By introducing defer statements we can ensure that the socket is always closed.