Skip to content

Commit

Permalink
Merge pull request #2455 from SmartManoj/patch-1
Browse files Browse the repository at this point in the history
Use environment var for ResolveIPAddressTimeout
  • Loading branch information
jandubois authored Aug 8, 2024
2 parents edb53b3 + 37fc2fd commit 200db6d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/networks/usernet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"net"
"net/http"
"os"
"strconv"
"time"

gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client"
Expand Down Expand Up @@ -74,11 +76,19 @@ func (c *Client) ResolveAndForwardSSH(ipAddr string, sshPort int) error {
}

func (c *Client) ResolveIPAddress(ctx context.Context, vmMacAddr string) (string, error) {
timeout := time.After(2 * time.Minute)
resolveIPAddressTimeout := 2 * time.Minute
resolveIPAddressTimeoutEnv := os.Getenv("LIMA_USERNET_RESOLVE_IP_ADDRESS_TIMEOUT")
if resolveIPAddressTimeoutEnv != "" {
if parsedTimeout, err := strconv.Atoi(resolveIPAddressTimeoutEnv); err == nil {
resolveIPAddressTimeout = time.Duration(parsedTimeout) * time.Minute
}
}
ctx, cancel := context.WithTimeout(ctx, resolveIPAddressTimeout)
defer cancel()
ticker := time.NewTicker(500 * time.Millisecond)
for {
select {
case <-timeout:
case <-ctx.Done():
return "", errors.New("usernet unable to resolve IP for SSH forwarding")
case <-ticker.C:
leases, err := c.Leases(ctx)
Expand Down

0 comments on commit 200db6d

Please sign in to comment.