Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait for ipv4 to be set #173

Merged
merged 18 commits into from
Feb 6, 2025
Merged
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- 'release/**'
pull_request:
branches:
- '**'
Expand All @@ -12,9 +13,6 @@ on:
- synchronize
workflow_dispatch:

env:
DOCKER_API_VERSION: '1.45'

jobs:
docker-e2e:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI=
github.com/docker/docker v27.3.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
Expand Down
2 changes: 1 addition & 1 deletion core/provider/digitalocean/droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (t *Task) waitForDockerStart(ctx context.Context) error {

ip, err := t.GetIP(ctx)

if err != nil {
if err != nil || ip == "" {
t.logger.Debug("task does not have ipv4 address", zap.Error(err), zap.String("task", t.GetState().Name))
return false, err
}
Expand Down
3 changes: 2 additions & 1 deletion core/provider/digitalocean/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"strconv"
"strings"
"sync"
"tailscale.com/tsnet"
"time"

"tailscale.com/tsnet"

"github.com/digitalocean/godo"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
Expand Down
6 changes: 4 additions & 2 deletions core/provider/digitalocean/tailscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"

"github.com/skip-mev/petri/core/v3/util"
"go.uber.org/zap"
"strings"
"tailscale.com/ipn/ipnstate"
"time"
)

func (t *Task) launchTailscale(ctx context.Context, authKey string, tags []string) (string, error) {
Expand Down Expand Up @@ -106,5 +107,6 @@ func (t *Task) getTailscaleIp(ctx context.Context) (string, error) {
return "", errors.New("no IPv4 Tailscale address found")
}

t.logger.Debug("tailscale ips", zap.Any("ips", status.TailscaleIPs))
return status.TailscaleIPs[0].String(), nil
}
26 changes: 21 additions & 5 deletions core/provider/digitalocean/task.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package digitalocean

import (
"al.essio.dev/pkg/shellescape"
"bytes"
"context"
"fmt"
Expand All @@ -10,9 +9,11 @@ import (
"strconv"
"strings"
"sync"
"tailscale.com/tsnet"
"time"

"al.essio.dev/pkg/shellescape"
"tailscale.com/tsnet"

"golang.org/x/crypto/ssh"

"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -266,13 +267,28 @@ func (t *Task) GetIP(ctx context.Context) (string, error) {
return t.getTailscaleIp(ctx)
}

droplet, err := t.getDroplet(ctx)
var ip string
err := util.WaitForCondition(ctx, 60*time.Second, 1*time.Second, func() (bool, error) {
droplet, err := t.getDroplet(ctx)
if err != nil {
return false, err
}

ipv4, err := droplet.PublicIPv4()
if err != nil {
return false, err
}
t.logger.Debug("task public ipv4: " + ipv4)

ip = ipv4
return ip != "", nil
})

if err != nil {
return "", err
return "", fmt.Errorf("failed to get valid IP address after retries: %w", err)
}

return droplet.PublicIPv4()
return ip, nil
}

func (t *Task) GetExternalAddress(ctx context.Context, port string) (string, error) {
Expand Down
Loading
Loading