Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/app/pipedv1/plugin/ecs/deployment/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ func (f *fakeLogPersister) Complete(time.Duration) error { return nil }
type mockECSClient struct {
CreateServiceFunc func(ctx context.Context, service types.Service) (*types.Service, error)
UpdateServiceFunc func(ctx context.Context, service types.Service) (*types.Service, error)
DescribeServiceFunc func(ctx context.Context, service types.Service) (*types.Service, error)
GetServiceTaskSetsFunc func(ctx context.Context, service types.Service) ([]types.TaskSet, error)
GetPrimaryTaskSetFunc func(ctx context.Context, service types.Service) (*types.TaskSet, error)
CreateTaskSetFunc func(ctx context.Context, service types.Service, taskDefinition types.TaskDefinition, targetGroup *types.LoadBalancer, scale float64) (*types.TaskSet, error)
UpdateServicePrimaryTaskSetFunc func(ctx context.Context, service types.Service, taskSet types.TaskSet) (*types.TaskSet, error)
DeleteTaskSetFunc func(ctx context.Context, taskSet types.TaskSet) error
GetTasksFunc func(ctx context.Context, service types.Service) ([]types.Task, error)
ServiceExistsFunc func(ctx context.Context, cluster, serviceName string) (bool, error)
GetServiceStatusFunc func(ctx context.Context, cluster, serviceName string) (string, error)
WaitServiceStableFunc func(ctx context.Context, cluster, serviceName string) error
Expand All @@ -65,6 +67,9 @@ func (m *mockECSClient) CreateService(ctx context.Context, service types.Service
func (m *mockECSClient) UpdateService(ctx context.Context, service types.Service) (*types.Service, error) {
return m.UpdateServiceFunc(ctx, service)
}
func (m *mockECSClient) DescribeService(ctx context.Context, service types.Service) (*types.Service, error) {
return m.DescribeServiceFunc(ctx, service)
}
func (m *mockECSClient) GetServiceTaskSets(ctx context.Context, service types.Service) ([]types.TaskSet, error) {
return m.GetServiceTaskSetsFunc(ctx, service)
}
Expand All @@ -80,6 +85,9 @@ func (m *mockECSClient) UpdateServicePrimaryTaskSet(ctx context.Context, service
func (m *mockECSClient) DeleteTaskSet(ctx context.Context, taskSet types.TaskSet) error {
return m.DeleteTaskSetFunc(ctx, taskSet)
}
func (m *mockECSClient) GetTasks(ctx context.Context, service types.Service) ([]types.Task, error) {
return m.GetTasksFunc(ctx, service)
}
func (m *mockECSClient) ServiceExists(ctx context.Context, cluster, serviceName string) (bool, error) {
return m.ServiceExistsFunc(ctx, cluster, serviceName)
}
Expand Down
65 changes: 65 additions & 0 deletions pkg/app/pipedv1/plugin/ecs/livestate/fetcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2026 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package livestate

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/ecs/provider"
)

// ECSFetcher fetches the current state of an ECS application's resources
type ECSFetcher struct {
client provider.Client
}

// QueryResources fetches the live Service, its PipeCD-managed TaskSets, and all Tasks for the given service descriptor
func (w *ECSFetcher) FetchResources(ctx context.Context, service types.Service) (*queryResourcesResult, error) {
liveService, err := w.client.DescribeService(ctx, service)
if err != nil {
return nil, err
}

// GetServiceTaskSets filters out DRAINING task sets and task sets not created by Pipecd,
// so the result only contains task sets that Pipecd is responsible for
tasksets, err := w.client.GetServiceTaskSets(ctx, *liveService)
if err != nil {
return nil, err
}

// Tasks are fetched for the whole service rather than per task set.
// Grouping tasks under their parent task set is deferred to the caller.
tasks, err := w.client.GetTasks(ctx, *liveService)
if err != nil {
return nil, err
}

return &queryResourcesResult{
Service: liveService,
TaskSets: tasksets,
Tasks: tasks,
}, nil
}

// queryResourcesResult holds the raw AWS objects for a single ECS application.
//
// Tasks are a flat list, not group by taskset ID yet
type queryResourcesResult struct {
Service *types.Service
TaskSets []types.TaskSet
Tasks []types.Task
}
Loading
Loading