Skip to content

Commit

Permalink
fix: delete workspace even if connection can not be made (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak authored Sep 9, 2024
1 parent cbe4660 commit 3b8c853
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
24 changes: 11 additions & 13 deletions pkg/provider/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ func (p *DigitalOceanProvider) DestroyWorkspace(workspaceReq *provider.Workspace
dockerClient, err := p.getDockerClient(workspaceReq.Workspace.Id)
if err != nil {
logWriter.Write([]byte("Failed to get docker client: " + err.Error() + "\n"))
return new(provider_util.Empty), err
}

sshClient, err := p.getSshClient(workspaceReq.Workspace.Id)
if err != nil {
logWriter.Write([]byte("Failed to get ssh client: " + err.Error() + "\n"))
return new(provider_util.Empty), err
}
defer sshClient.Close()
} else {
sshClient, err := p.getSshClient(workspaceReq.Workspace.Id)
if err != nil {
logWriter.Write([]byte("Failed to get ssh client: " + err.Error() + "\n"))
} else {
defer sshClient.Close()

err = dockerClient.DestroyWorkspace(workspaceReq.Workspace, p.getWorkspaceDir(workspaceReq.Workspace.Id), sshClient)
if err != nil {
logWriter.Write([]byte("Failed to destroy workspace: " + err.Error() + "\n"))
return new(provider_util.Empty), err
err = dockerClient.DestroyWorkspace(workspaceReq.Workspace, p.getWorkspaceDir(workspaceReq.Workspace.Id), sshClient)
if err != nil {
logWriter.Write([]byte("Failed to destroy workspace: " + err.Error() + "\n"))
}
}
}

targetOptions, err := types.ParseTargetOptions(workspaceReq.TargetOptions)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (p *DigitalOceanProvider) waitForDial(workspaceId string, dialTimeout time.
dialStartTime := time.Now()
for {
if time.Since(dialStartTime) > dialTimeout {
return errors.New("timeout: dialing timed out after 3 minutes")
return fmt.Errorf("timeout: dialing timed out after %f minutes", dialTimeout.Minutes())
}

dialConn, err := tsnetConn.Dial(context.Background(), "tcp", fmt.Sprintf("%s:%d", workspaceId, config.SSH_PORT))
Expand Down

0 comments on commit 3b8c853

Please sign in to comment.