Skip to content

Commit a2e18d7

Browse files
authored
Support ECS capacity provider strategy (#6331)
1 parent ad30e43 commit a2e18d7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

pkg/app/piped/platformprovider/ecs/client.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ func (c *client) CreateService(ctx context.Context, service types.Service) (*typ
8787
if service.DeploymentController == nil || service.DeploymentController.Type != types.DeploymentControllerTypeExternal {
8888
return nil, fmt.Errorf("failed to create ECS service %s: deployment controller of type EXTERNAL is required", *service.ServiceName)
8989
}
90+
if service.LaunchType != "" && service.CapacityProviderStrategy != nil {
91+
return nil, fmt.Errorf("failed to create ECS service %s: launch type and capacity provider strategy cannot be specified together", *service.ServiceName)
92+
}
9093
input := &ecs.CreateServiceInput{
9194
Cluster: service.ClusterArn,
9295
ServiceName: service.ServiceName,
@@ -104,6 +107,12 @@ func (c *client) CreateService(ctx context.Context, service types.Service) (*typ
104107
SchedulingStrategy: service.SchedulingStrategy,
105108
Tags: service.Tags,
106109
}
110+
if service.LaunchType != "" {
111+
input.LaunchType = service.LaunchType
112+
}
113+
if service.CapacityProviderStrategy != nil {
114+
input.CapacityProviderStrategy = service.CapacityProviderStrategy
115+
}
107116
output, err := c.ecsClient.CreateService(ctx, input)
108117
if err != nil {
109118
return nil, fmt.Errorf("failed to create ECS service %s: %w", *service.ServiceName, err)
@@ -136,6 +145,9 @@ func (c *client) PruneServiceTasks(ctx context.Context, service types.Service) e
136145
}
137146

138147
func (c *client) UpdateService(ctx context.Context, service types.Service) (*types.Service, error) {
148+
if service.LaunchType != "" && service.CapacityProviderStrategy != nil {
149+
return nil, fmt.Errorf("failed to update ECS service %s: launch type and capacity provider strategy cannot be specified together", *service.ServiceName)
150+
}
139151
input := &ecs.UpdateServiceInput{
140152
Cluster: service.ClusterArn,
141153
Service: service.ServiceName,
@@ -152,6 +164,10 @@ func (c *client) UpdateService(ctx context.Context, service types.Service) (*typ
152164
input.DesiredCount = aws.Int32(service.DesiredCount)
153165
}
154166

167+
if service.CapacityProviderStrategy != nil {
168+
input.CapacityProviderStrategy = service.CapacityProviderStrategy
169+
}
170+
155171
output, err := c.ecsClient.UpdateService(ctx, input)
156172
if err != nil {
157173
return nil, fmt.Errorf("failed to update ECS service %s: %w", *service.ServiceName, err)
@@ -241,6 +257,9 @@ func (c *client) CreateTaskSet(ctx context.Context, service types.Service, taskD
241257
if taskDefinition.TaskDefinitionArn == nil {
242258
return nil, fmt.Errorf("failed to create task set of task family %s: no task definition provided", *taskDefinition.Family)
243259
}
260+
if service.LaunchType != "" && service.CapacityProviderStrategy != nil {
261+
return nil, fmt.Errorf("failed to create task set of task family %s: launch type and capacity provider strategy cannot be specified together", *taskDefinition.Family)
262+
}
244263

245264
input := &ecs.CreateTaskSetInput{
246265
Cluster: service.ClusterArn,
@@ -251,12 +270,18 @@ func (c *client) CreateTaskSet(ctx context.Context, service types.Service, taskD
251270
// If you specify the awsvpc network mode, the task is allocated an elastic network interface,
252271
// and you must specify a NetworkConfiguration when run a task with the task definition.
253272
NetworkConfiguration: service.NetworkConfiguration,
254-
LaunchType: service.LaunchType,
255273
ServiceRegistries: service.ServiceRegistries,
256274
}
275+
if service.LaunchType != "" {
276+
input.LaunchType = service.LaunchType
277+
}
278+
if service.CapacityProviderStrategy != nil {
279+
input.CapacityProviderStrategy = service.CapacityProviderStrategy
280+
}
257281
if targetGroup != nil {
258282
input.LoadBalancers = []types.LoadBalancer{*targetGroup}
259283
}
284+
260285
output, err := c.ecsClient.CreateTaskSet(ctx, input)
261286
if err != nil {
262287
return nil, fmt.Errorf("failed to create ECS task set %s: %w", *taskDefinition.TaskDefinitionArn, err)

0 commit comments

Comments
 (0)