-
Notifications
You must be signed in to change notification settings - Fork 42
cleanup function will return the code which ssh returns #445
cleanup function will return the code which ssh returns #445
Conversation
Hi @dansible ,
BTW the openstack infra itself is not very stable - in your case i saw you were unable to ssh to gctl-os shoot but today i can ssh without error, this is the same when i was doing gardenctl ssh openstack_node - sometimes the ssh failed for unknown reason...i didn't dig out why, retry will success.... |
pkg/cmd/ssh_openstack.go
Outdated
} | ||
defer a.cleanUpOpenstack(sshStatus) |
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.
what's the purpose of having defer
as last statement of the function? I would refrain from moving the deferred cleanup call to the bottom.
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.
during my test, if i move the defer a.cleanUpOpenstack(sshStatus)
to above lines of value assignment of sshStatus
, it won't get correct values.
Say if i keep defer a.cleanUpOpenstack(sshStatus)
to original line, when some error occurs in ssh, sshStatus
will be assigned with value 1 (for example) but in defer a.cleanUpOpenstack(sshStatus)
the value of sshStatus
is still 0
do you have a better idea how i can get sshStatus
correctly passed to cleanUpOpenstack
meanwhile i can keep the original line for the defer function? thanks!
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 you want to achieve this you need to pass a pointer
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! i will have a try
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 @petersutter , i've modified the code using *int to pass values, thanks for your suggestion!
-Neo
6204f9b
to
1a544ae
Compare
…ction in ssh_openstack.go
@dansible , per our discussion in planning mtg this week, i implement a function to check whether IP and port are reachable (#448) , i implement this feature in this PR as this function will impact the overall exit status so i append this feature together in this PR. Please review it when you have time, thanks! |
pkg/cmd/utils.go
Outdated
attemptCnt := 0 | ||
for attemptCnt < 6 { | ||
ncCmd := fmt.Sprintf("timeout 10 nc -vtnz %s %s", ip, port) | ||
cmd := exec.Command("bash", "-c", ncCmd) |
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.
- Stop calling bash
- Use
exec. CommandContext
to pass a context with a timeout to achieve the same behavior instead of callingtimeout
- Does this work on windows? I'd rather prefer a native-go solution
thanks @petersutter , i used go native method to check whether the ip and port reachable |
timeout := time.Second * 60 | ||
conn, err := net.DialTimeout("tcp", net.JoinHostPort(ip, port), 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.
and this works without having to dial/try multiple times within a certain amount of time?
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.
Yes, in my test it tries within 1 min, as I set in the 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.
/lgtm
What this PR does / why we need it:
cleanup function will return the code which ssh returns
Which issue(s) this PR fixes:
Fixes #444 and #448
Special notes for your reviewer:
Release note: