Skip to content

Commit c4f1b3a

Browse files
committed
Fix issue that SSH not ready after creation
1 parent 5fa810b commit c4f1b3a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/stackit/network.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ package stackit
22

33
import (
44
"context"
5+
"fmt"
6+
"net"
7+
"time"
58

9+
"github.com/loft-sh/devpod/pkg/ssh"
10+
"github.com/pkg/errors"
611
"github.com/stackitcloud/stackit-sdk-go/core/utils"
712
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
813
"github.com/stackitcloud/stackit-sdk-go/services/iaas/wait"
14+
15+
"github.com/stackitcloud/devpod-provider-stackit/pkg/options"
916
)
1017

1118
func (s *Stackit) createNetwork(ctx context.Context, projectId string, networkName string) (*iaas.Network, error) {
@@ -42,3 +49,27 @@ func (s *Stackit) deleteNetwork(ctx context.Context, projectId string, networkId
4249
}
4350
return nil
4451
}
52+
53+
func (s *Stackit) waitForSSHToBeReady(options *options.Options, publicIP, sshUserName, sshPort string) error {
54+
// Get private key
55+
privateKey, err := ssh.GetPrivateKeyRawBase(options.MachineFolder)
56+
if err != nil {
57+
return errors.Wrap(err, "load private key")
58+
}
59+
60+
sshSuccess := false
61+
for !sshSuccess {
62+
sshClient, err := ssh.NewSSHClient(sshUserName, net.JoinHostPort(publicIP, sshPort), privateKey)
63+
if err == nil {
64+
sshSuccess = true
65+
err := sshClient.Close()
66+
if err != nil {
67+
return err
68+
}
69+
} else {
70+
fmt.Println("SSH not ready...")
71+
time.Sleep(5 * time.Second)
72+
}
73+
}
74+
return nil
75+
}

pkg/stackit/stackit.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ func (s *Stackit) Create(ctx context.Context, options *options.Options, publicKe
276276
return err
277277
}
278278

279+
err = s.waitForSSHToBeReady(options, publicIP.GetIp(), SSHUserName, SSHPort)
280+
if err != nil {
281+
return err
282+
}
283+
279284
return nil
280285
}
281286

0 commit comments

Comments
 (0)