-
Notifications
You must be signed in to change notification settings - Fork 243
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
Add preflight check for vsock SSH port #3965
Conversation
ee58bc8
to
6e4e309
Compare
working as expected, tested on macOS:
|
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.
Just added a few minor comments
if err != nil { | ||
return fmt.Errorf("port %d already in use: %s", constants.VsockSSHPort, err) | ||
} | ||
server.Close() |
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.
server.Close() | |
defer func() { | |
err = server.Close() | |
}() | |
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.
Could be just return server.Close()
?
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 think it's more conventional to use defer for closing connections.
server.Close() | ||
|
||
// we successfully used and closed the port | ||
return nil |
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.
return nil | |
return err |
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.
If the intent is to return the error from the deferred server.Close()
call, I don't think this will work as expected:
https://go.dev/play/p/HyKboZE2dka
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.
You are right. We can define the err variable as part of the function signature to set the correct return value in defer.
https://go.dev/play/p/8kaB3HQlfk6
} | ||
|
||
func checkSSHPortFree() func() error { | ||
return func() error { |
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.
Do you need this indirection? the preflights use the pattern func foo() func() error
when we need to pass arguments to foo
. In this case, I think you could directly use func checkSSHPortFree() error
, and change check: checkSSHPortFree(),
to check: checkSSHPortFree,
?
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.
Thinking more about it, it actually would make sense to only run the preset when usermode networking is use (the network-mode
config option). In which case you'd need additional arg to the check, and using this pattern would make sense :)
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 don't know why this was closed as resolved, but this was neither discussed nor resolved.
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.
server.Close() | ||
|
||
// we successfully used and closed the port | ||
return nil |
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.
If the intent is to return the error from the deferred server.Close()
call, I don't think this will work as expected:
https://go.dev/play/p/HyKboZE2dka
if err != nil { | ||
return fmt.Errorf("port %d already in use: %s", constants.VsockSSHPort, err) | ||
} | ||
server.Close() |
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.
Could be just return server.Close()
?
Signed-off-by: Yevhen Vydolob <[email protected]>
Co-authored-by: Gunjan Vyas <[email protected]>
25768d0
to
7e92185
Compare
@evidolob: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/approve |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vyasgun The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Relates to: First part for #3855
Solution/Idea
PR's add preflight check for SSH port(
2222
) in not used before start.Testing
2222
port on your laptop( you may usenc -lkv 127.0.0.1 2222
command)2222