Skip to content

Commit

Permalink
Retry "tart ip" up to 10 times (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev authored Aug 8, 2024
1 parent 494b75e commit cbb18ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
16 changes: 0 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ linters:
- whitespace

disable:
# Messages like "struct of size 104 bytes could be of size 96 bytes" from a package
# that was last updated 2 years ago[1] are barely helpful.
#
# After all, we're writing the code for other people, so let's trust the compiler here (that's
# constantly evolving compared to this linter) and revisit this if memory usage becomes a problem.
#
# [1]: https://github.com/mdempsky/maligned/commit/6e39bd26a8c8b58c5a22129593044655a9e25959
- maligned

# We don't have high-performance requirements at this moment, so sacrificing
# the code readability for marginal performance gains is not worth it.
- prealloc
Expand All @@ -75,19 +66,12 @@ linters:
# Unfortunately, we use globals due to how spf13/cobra works.
- gochecknoglobals

# That's fine that some Proto objects don't have all fields initialized
- exhaustivestruct

# Style linters that are total nuts.
- wsl
- gofumpt
- goimports
- funlen

# This conflicts with the Protocol Buffers Version 3 design,
# which is largely based on default values for struct fields.
- exhaustivestruct

# Enough parallelism for now.
- paralleltest

Expand Down
17 changes: 15 additions & 2 deletions internal/tart/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,23 @@ func (vm *VM) MonitorTartRunOutput() {
}

func (vm *VM) OpenSSH(ctx context.Context, config Config) (*ssh.Client, error) {
ip, err := vm.IP(ctx, config)
if err != nil {
var ip string
var err error

if err := retry.Do(func() error {
ip, err = vm.IP(ctx, config)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to retrieve IP address of VM %q in 60 seconds: %v, "+
"will re-try...", vm.id, err)

return err
}

return nil
}, retry.Context(ctx), retry.DelayType(retry.FixedDelay), retry.Delay(time.Second)); err != nil {
return nil, err
}

addr := fmt.Sprintf("%s:%d", ip, config.SSHPort)

sshConfig := &ssh.ClientConfig{
Expand Down

0 comments on commit cbb18ff

Please sign in to comment.