diff --git a/core/provider/docker/network.go b/core/provider/docker/network.go index 8392380..f18d42c 100644 --- a/core/provider/docker/network.go +++ b/core/provider/docker/network.go @@ -141,8 +141,6 @@ func (p *Provider) nextAvailableIP() (string, error) { return "", err } - p.state.AllocatedIPs = append(p.state.AllocatedIPs, ip.To4().String()) - return ip.String(), nil } diff --git a/core/provider/docker/provider.go b/core/provider/docker/provider.go index 2c4ec37..ffedc8b 100644 --- a/core/provider/docker/provider.go +++ b/core/provider/docker/provider.go @@ -223,7 +223,6 @@ func (p *Provider) CreateTask(ctx context.Context, definition provider.TaskDefin logger.Debug("creating container", zap.String("name", definition.Name), zap.String("image", definition.Image.Image)) - // network map is volatile, so we need to mutex update it ip, err := p.nextAvailableIP() if err != nil { return nil, err diff --git a/core/provider/docker/provider_test.go b/core/provider/docker/provider_test.go index 10ec0c2..fe92245 100644 --- a/core/provider/docker/provider_test.go +++ b/core/provider/docker/provider_test.go @@ -3,16 +3,15 @@ package docker_test import ( "context" "fmt" - "sync" - "testing" - "time" - "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" - gonanoid "github.com/matoous/go-nanoid/v2" + "github.com/matoous/go-nanoid/v2" "github.com/skip-mev/petri/core/v2/provider/docker" "go.uber.org/zap/zaptest" + "sync" + "testing" + "time" "github.com/skip-mev/petri/core/v2/provider" "github.com/stretchr/testify/assert" @@ -48,9 +47,9 @@ func TestCreateProviderDuplicateNetwork(t *testing.T) { p1, err := docker.CreateProvider(ctx, logger, providerName) require.NoError(t, err) - defer func() { - require.NoError(t, p1.Teardown(context.Background())) - }() + defer func(ctx context.Context, p provider.ProviderI) { + require.NoError(t, p.Teardown(ctx)) + }(ctx, p1) p2, err := docker.CreateProvider(ctx, logger, providerName) require.Error(t, err) @@ -67,9 +66,9 @@ func TestCreateProvider(t *testing.T) { p, err := docker.CreateProvider(ctx, logger, providerName) require.NoError(t, err) - defer func() { + defer func(ctx context.Context, p provider.ProviderI) { require.NoError(t, p.Teardown(ctx)) - }() + }(ctx, p) state := p.GetState() assert.Equal(t, providerName, state.Name) @@ -107,9 +106,10 @@ func TestCreateTask(t *testing.T) { p, err := docker.CreateProvider(context.Background(), logger, providerName) require.NoError(t, err) - defer func() { + + defer func(ctx context.Context, p provider.ProviderI) { require.NoError(t, p.Teardown(ctx)) - }() + }(ctx, p) tests := []struct { name string @@ -182,9 +182,10 @@ func TestConcurrentTaskCreation(t *testing.T) { p, err := docker.CreateProvider(ctx, logger, providerName) require.NoError(t, err) - defer func() { + + defer func(ctx context.Context, p provider.ProviderI) { require.NoError(t, p.Teardown(ctx)) - }() + }(ctx, p) numTasks := 10 var wg sync.WaitGroup @@ -248,9 +249,10 @@ func TestProviderSerialization(t *testing.T) { p1, err := docker.CreateProvider(ctx, logger, providerName) require.NoError(t, err) - defer func() { - require.NoError(t, p1.Teardown(ctx)) - }() + + defer func(ctx context.Context, p provider.ProviderI) { + require.NoError(t, p.Teardown(ctx)) + }(ctx, p1) _, err = p1.CreateTask(ctx, provider.TaskDefinition{ Name: fmt.Sprintf("%s-test-task", providerName), diff --git a/core/provider/docker/task.go b/core/provider/docker/task.go index eddbb7b..f4ad430 100644 --- a/core/provider/docker/task.go +++ b/core/provider/docker/task.go @@ -4,23 +4,14 @@ import ( "bytes" "context" "fmt" - "sync" - "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/go-connections/nat" - "github.com/skip-mev/petri/core/v2/util" - - // "github.com/docker/docker/api/types/filters" - // "github.com/docker/docker/api/types/image" - // "github.com/docker/docker/api/types/mount" - // "github.com/docker/docker/api/types/network" - // "github.com/docker/docker/pkg/stdcopy" - // "github.com/docker/go-connections/nat" - "time" - "github.com/skip-mev/petri/core/v2/provider" + "github.com/skip-mev/petri/core/v2/util" "go.uber.org/zap" + "sync" + "time" ) type TaskState struct { @@ -29,7 +20,7 @@ type TaskState struct { Volume *VolumeState `json:"volumes"` Definition provider.TaskDefinition `json:"definition"` Status provider.TaskStatus `json:"status"` - IpAddress string `json:"ip_address"` + IpAddress string `json:"ip_address"` } type VolumeState struct { @@ -162,8 +153,6 @@ func (t *Task) GetStatus(ctx context.Context) (provider.TaskStatus, error) { return provider.TASK_STATUS_UNDEFINED, err } - fmt.Println(containerJSON.State.Status) - switch state := containerJSON.State.Status; state { case "created": return provider.TASK_STOPPED, nil @@ -184,10 +173,6 @@ func (t *Task) GetStatus(ctx context.Context) (provider.TaskStatus, error) { return provider.TASK_STATUS_UNDEFINED, nil } -func (t *Task) Initialize(ctx context.Context) error { - return nil -} - func (t *Task) Modify(ctx context.Context, td provider.TaskDefinition) error { panic("unimplemented") }