Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

fix aws ssh issue #446

Merged
merged 7 commits into from
Nov 24, 2020

Conversation

neo-liang-sap
Copy link
Contributor

@neo-liang-sap neo-liang-sap commented Nov 16, 2020

What this PR does / why we need it:
fix aws ssh issue
Which issue(s) this PR fixes:
Fixes #442

Special notes for your reviewer:

  1. in my env, nc -vtnz ip port returns sth like 127.0.0.1 49269 open so the result should grep open, instead of succeed
    not sure my nc is correct one
nc --version                                               (ccee-m3/default)
netcat (The GNU Netcat) 0.7.1
Copyright (C) 2002 - 2003  Giovanni Giacobbi

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program under the terms of
the GNU General Public License.
For more information about these matters, see the file named COPYING.

Original idea and design by Avian Research <hobbit@avian.org>,
Written by Giovanni Giacobbi <giovanni@giacobbi.net>.
  1. fix a small typo, shh to ssh

  2. when bastion exist, a.BastionPrivIP and a.BastionIP should also be assigned with values (like what they are treat in non bastion exist path) , otherwise following step will fail due to these two properties empty

Release note:

fix aws ssh issue

@neo-liang-sap neo-liang-sap requested a review from a team as a code owner November 16, 2020 05:32
@gardener-robot gardener-robot added needs/review Needs review size/xs Size of pull request is tiny (see gardener-robot robot/bots/size.py) labels Nov 16, 2020
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 16, 2020
@neo-liang-sap
Copy link
Contributor Author

testing result
image

dansible
dansible previously approved these changes Nov 19, 2020
@gardener-robot gardener-robot removed the needs/review Needs review label Nov 19, 2020
@dansible dansible dismissed their stale review November 19, 2020 20:54

The string output check should be succeeded

@@ -242,7 +246,7 @@ func (a *AwsInstanceAttribute) sshPortCheck() {
cmd := exec.Command("bash", "-c", ncCmd)
output, _ := cmd.CombinedOutput()
fmt.Println("=>", string(output))
if strings.Contains(string(output), "succeeded") {
if strings.Contains(string(output), "open") {
Copy link
Contributor

@dansible dansible Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should be succeeded.

With open, I get:

Bastion host instance running.
Opened SSH Port on Node.
Waiting 60 seconds for Bastion SSH port open
=> Connection to ... port 22 [tcp/*] succeeded!

=> Connection to ... port 22 [tcp/*] succeeded!

=> Connection to ... port 22 [tcp/*] succeeded!

=> Connection to ... port 22 [tcp/*] succeeded!

=> Connection to ... port 22 [tcp/*] succeeded!

=> Connection to ... port 22 [tcp/*] succeeded!

	SSH Port Open on Bastion TimeOut
(4/4) Cleanup
Cleaning up bastion host configurations...

With succeeded:

Bastion host instance running.
Opened SSH Port on Node.
Waiting 60 seconds for Bastion SSH port open
=> Connection to ... port 22 [tcp/*] succeeded!

Opened SSH Port on Bastion
SSH gardener@... => gardener@ip-...compute.internal
Warning: Permanently added '...' (ED25519) to the list of known hosts.
Warning: Permanently added 'ip-....compute.internal' (ED25519) to the list of known hosts.
(4/4) Cleanup
Cleaning up bastion host configurations...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dansible , i used a newly introduced function CheckIPPortReachable which is using native go code (so we don't have dependency on different version of binary like your nc returns succeeded but mine returns open) to perform ssh port check

@gardener-robot gardener-robot added the needs/changes Needs (more) changes label Nov 19, 2020
@@ -242,7 +246,7 @@ func (a *AwsInstanceAttribute) sshPortCheck() {
cmd := exec.Command("bash", "-c", ncCmd)
output, _ := cmd.CombinedOutput()
fmt.Println("=>", string(output))
if strings.Contains(string(output), "succeeded") {
if strings.Contains(string(output), "open") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of sshPortCheck(), can't we reuse the newly introduced [function]?(https://github.com/gardener/gardenctl/pull/445/files#diff-8a970d51dea43e926c0b913c26887464b362c5f723fb1d740a5a07d428434c07R355)

func CheckIPPortReachable(ip string, port string) error 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @petersutter , i add retry logic in CheckIPPortReachable function and use it here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I was asking in the other PR #445 (comment)

and this works without having to dial/try multiple times within a certain amount of time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, previously i though it was working as retry but later i found it's not, so i added the logic

@gardener-robot-ci-3 gardener-robot-ci-3 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 19, 2020
@gardener-robot gardener-robot added size/s Size of pull request is small (see gardener-robot robot/bots/size.py) and removed size/xs Size of pull request is tiny (see gardener-robot robot/bots/size.py) labels Nov 20, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 20, 2020
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 20, 2020
pkg/cmd/utils.go Outdated
fmt.Printf("IP %s port %s is reachable\n", ip, port)
return nil
}
time.Sleep(time.Second * 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a need to sleep 10 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i removed this line

pkg/cmd/utils.go Outdated
@@ -349,17 +349,22 @@ func PrintoutObject(objectToPrint interface{}, writer io.Writer, outputFormat st
return nil
}

//CheckIPPortReachable check whether IP with port is reachable with 1 min
//CheckIPPortReachable check whether IP with port is reachable with 2 min
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//CheckIPPortReachable check whether IP with port is reachable with 2 min
//CheckIPPortReachable check whether IP with port is reachable within 2 min

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i fixed the typo

pkg/cmd/utils.go Outdated
timeout := time.Second * 10
conn, err := net.DialTimeout("tcp", net.JoinHostPort(ip, port), timeout)
if err != nil {
fmt.Println("Connecting error:", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either omit the error as long as you are retrying or add a hint in case another try is made

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i omitted the error

@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 20, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 20, 2020
@neo-liang-sap
Copy link
Contributor Author

build failed due to #455 ,

@petersutter
Copy link
Contributor

build failed due to #455 ,

How could this even happen in the first place, that code slips into master that produces build errors?

@neo-liang-sap
Copy link
Contributor Author

#455

it's very wired - code is in #431 which has all CI check passed.... but actually this PR has some errors...i've notified PR owner to fix this

image

@gardener-attic gardener-attic deleted a comment from gardener-robot Nov 21, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2020
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2020
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2020
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2020
@neo-liang-sap
Copy link
Contributor Author

all check passed after #455 is fixed , @petersutter could you please review this PR when you have time? thanks!
-Neo

pkg/cmd/utils.go Outdated
defer conn.Close()
fmt.Printf("IP %s port %s is reachable\n", ip, port)
return nil
attemptCnt := 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would rather name it attemptCount or just attempt.

Copy link
Contributor

@petersutter petersutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
feel free to also change the variable name as suggested.

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging needs/changes Needs (more) changes and removed needs/changes Needs (more) changes reviewed/lgtm Has approval for merging labels Nov 23, 2020
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 24, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 24, 2020
@neo-liang-sap neo-liang-sap merged commit 4557f92 into gardener-attic:master Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs/changes Needs (more) changes needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) size/s Size of pull request is small (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gardenctl ssh <aws_node> fails with InvalidParameterValue
7 participants