Skip to content

Commit

Permalink
FIX: Catch ssh error
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred78290 committed Aug 13, 2024
1 parent 58107bd commit 0029af3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion providers/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func (config *configurationTest) WaitSSHReady(nodename, address string) error {
return context.PollImmediate(time.Second, time.Duration(config.appConfig.SSH.WaitSshReadyInSeconds)*time.Second, func() (done bool, err error) {
// Set hostname
if _, err := utils.Sudo(&config.appConfig.SSH, address, time.Second, fmt.Sprintf("hostnamectl set-hostname %s", nodename)); err != nil {
if strings.HasSuffix(err.Error(), "connection refused") || strings.HasSuffix(err.Error(), "i/o timeout") {
errMessage := err.Error()

if strings.HasSuffix(errMessage, "connection refused") || strings.HasSuffix(errMessage, "i/o timeout") || strings.Contains(errMessage, "handshake failed: EOF") || strings.Contains(errMessage, "connect: no route to host") {
return false, nil
}

Expand Down
6 changes: 4 additions & 2 deletions server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ func (vm *AutoScalerServerNode) WaitSSHReady(nodename, address string) error {
return context.PollImmediate(time.Second, time.Duration(config.SSH.WaitSshReadyInSeconds)*time.Second, func() (bool, error) {
// Set hostname
if _, err := utils.Sudo(config.SSH, address, time.Second, fmt.Sprintf("hostnamectl set-hostname %s", nodename)); err != nil {
if strings.HasSuffix(err.Error(), "connection refused") || strings.HasSuffix(err.Error(), "i/o timeout") || strings.Contains(err.Error(), "handshake failed") || strings.Contains(err.Error(), "connect: no route to host") {
errMessage := err.Error()

if strings.HasSuffix(errMessage, "connection refused") || strings.HasSuffix(errMessage, "i/o timeout") || strings.Contains(errMessage, "handshake failed: EOF") || strings.Contains(errMessage, "connect: no route to host") {
return false, nil
}

Expand Down Expand Up @@ -663,7 +665,7 @@ func (vm *AutoScalerServerNode) deleteVM(c client.ClientGenerator) error {
}

if err = vm.getKubernetesProvider().PrepareNodeDeletion(c, powered); err != nil {
glog.Errorf(constantes.ErrPrepareNodeDeletionFailed, vm.NodeName, err)
glog.Warnf(constantes.ErrPrepareNodeDeletionFailed, vm.NodeName, err)
}

if status.Powered() {
Expand Down

0 comments on commit 0029af3

Please sign in to comment.