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

Commit

Permalink
fix several gardenctl ssh aws issue
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-liang-sap committed Dec 1, 2020
1 parent 3381a5d commit 5194f9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/cmd/ssh_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (a *AwsInstanceAttribute) fetchAwsAttributes(targetReader TargetReader, nod
if a.FlagProviderID != "" {
arguments = fmt.Sprintf("ec2 describe-instances --filters Name=instance-id,Values=" + a.FlagProviderID + " --query Reservations[*].Instances[*].{VpcId:VpcId}")
} else {
arguments = fmt.Sprintf("ec2 describe-instances --filters Name=network-interface.private-dns-name,Values=" + nodeName + " --query Reservations[*].Instances[*].{VpcId:VpcId}")
arguments = fmt.Sprintf("ec2 describe-subnets --filters Name=subnet-id,Values=" + a.SubnetID + " --query Subnets[*].{VpcId:VpcId}")
}
a.VpcID = strings.Trim(operate("aws", arguments), "\n")

Expand All @@ -135,10 +135,16 @@ func (a *AwsInstanceAttribute) fetchAwsAttributes(targetReader TargetReader, nod

if a.FlagProviderID != "" {
arguments = fmt.Sprintf("ec2 describe-instances --filters Name=instance-id,Values=" + a.FlagProviderID + " --query Reservations[*].Instances[*].{ImageId:ImageId}")
a.ImageID = strings.Trim(operate("aws", arguments), "\n")
} else {
arguments = fmt.Sprintf("ec2 describe-instances --filters Name=network-interface.private-dns-name,Values=" + nodeName + " --query Reservations[*].Instances[*].{ImageId:ImageId}")
imageIDList := strings.Split(strings.TrimSuffix(strings.Trim(operate("aws", arguments), "\n"), "\n"), "\n")
if len(imageIDList) < 1 {
fmt.Println("there's no Image in this instance")
os.Exit(1)
}
a.ImageID = imageIDList[0]
}
a.ImageID = strings.Trim(operate("aws", arguments), "\n")

a.KeyName = a.ShootName + "-ssh-publickey"
a.UserData = getBastionUserData(a.SSHPublicKey)
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,19 @@ func PrintoutObject(objectToPrint interface{}, writer io.Writer, outputFormat st
return nil
}

//CheckIPPortReachable check whether IP with port is reachable within 1 min
//CheckIPPortReachable check whether IP with port is reachable within certain period of time
func CheckIPPortReachable(ip string, port string) error {
attemptCount := 0
for attemptCount < 6 {
for attemptCount < 12 {
timeout := time.Second * 10
conn, _ := net.DialTimeout("tcp", net.JoinHostPort(ip, port), timeout)
if conn != nil {
defer conn.Close()
fmt.Printf("IP %s port %s is reachable\n", ip, port)
return nil
}
fmt.Println("waiting for 10 seconds to retry")
time.Sleep(time.Second * 10)
attemptCount++
}
return fmt.Errorf("IP %s port %s is not reachable", ip, port)
Expand Down

0 comments on commit 5194f9e

Please sign in to comment.