Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b2af75
add a flag: ignoreDesiredCountOnUpdate
t-kikuc Jul 8, 2024
cf3efbf
ignore desiredCount on updateService if needed
t-kikuc Jul 8, 2024
d17a9b7
Add a flag ignoreDesiredCountOnUpdate into each func
t-kikuc Jul 8, 2024
5103158
Format func params and comment
t-kikuc Jul 8, 2024
dcd7dc9
add docs
t-kikuc Jul 8, 2024
7d65824
fix tests: add a missing attribute
t-kikuc Jul 8, 2024
2c8ef1a
recover desiredCount in CreateService (mistake)
t-kikuc Jul 8, 2024
a0f3459
add mentioning driftdetection
t-kikuc Jul 11, 2024
e556faf
Revert changes of adding ignoreDesiredCountOnUpdate
t-kikuc Jul 11, 2024
8ae6647
Revert commits of adding ignoreDesiredCount"
t-kikuc Jul 11, 2024
0bf97d5
Revert "add docs"
t-kikuc Jul 11, 2024
cd310a7
Revert "Format func params and comment"
t-kikuc Jul 11, 2024
638c5f9
Revert "Add a flag ignoreDesiredCountOnUpdate into each func"
t-kikuc Jul 11, 2024
936dfb2
Revert "ignore desiredCount on updateService if needed"
t-kikuc Jul 11, 2024
eb3bdc7
Revert "add a flag: ignoreDesiredCountOnUpdate"
t-kikuc Jul 11, 2024
766debd
ignore updating desiredCount if it's 0 or not defined
t-kikuc Jul 11, 2024
aef6c41
Merge branch 'master' of https://github.com/pipe-cd/pipecd into ecs-i…
t-kikuc Jul 11, 2024
434c3af
Use pruning when 'recreate' is on
t-kikuc Jul 11, 2024
7b267a1
add docs
t-kikuc Jul 11, 2024
33985f8
refine docs
t-kikuc Jul 11, 2024
e644dc0
Merge branch 'master' into ecs-ignore-desired-count
t-kikuc Jul 12, 2024
b58fb8c
Clarify procedure of configuring
t-kikuc Jul 16, 2024
99060a0
Merge branch 'ecs-ignore-desired-count' of https://github.com/pipe-cd…
t-kikuc Jul 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ One of `yamlField` or `regex` is required.

There are some restrictions in configuring a service definition file.

- As long as `desiredCount` is 0 or not set, `desiredCount` of your service will NOT be updated in deployments.
- If `desiredCount` is 0 or not set for a new service, the service's `desiredCount` will be 0.
- `capacityProviderStrategy` is not supported.
Comment on lines +519 to 521
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Ask] When enabling ECS autoscaling, what should users do? In my understanding, they set desiredCount to 0 after setting up autoscaling. Is it right?

Copy link
Member

@Warashi Warashi Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to sure. I have the same question.

Users can follow the below steps to create an autoscaled service. Is this correct?

  1. create a service with the desiredCount as 0 or not specified. if it is not specified, the desiredCount is treated as 0.
  2. configure autoscaling, and autoscaling policy or something like this updates desiredCount.
  3. when updating a service, piped ignores the desiredCount. So the count of tasks is not touched.

- `clientToken` is not supported.
- `deploymentController` is required and must be `EXTERNAL`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ spec:
- That means you need to link target groups to your listener rules before deployments.
- For more information and diagrams, see [Issue#4733 [ECS] Modify ELB listener rules other than defaults without adding config](https://github.com/pipe-cd/pipecd/pull/4733).
- When you use [Service Connect](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-connect.html), you cannot use Canary or Blue/Green deployment yet because Service Connect does not support the external deployment yet.
- When you use auto scaling for a service, you can avoid reconciling `desiredCount` by not setting `desiredCount` in the service definition. See [Restrictions of Service Definition](../../../configuration-reference/#restrictions-of-service-definition).

## Reference

Expand Down
3 changes: 1 addition & 2 deletions pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ func sync(ctx context.Context, in *executor.Input, platformProviderName string,
cnt := service.DesiredCount
// Scale down the service tasks by set it to 0
in.LogPersister.Infof("Scale down ECS desired tasks count to 0")
service.DesiredCount = 0
if _, err = client.UpdateService(ctx, *service); err != nil {
if err = client.PruneServiceTasks(ctx, *service); err != nil {
in.LogPersister.Errorf("Failed to stop service tasks: %v", err)
return false
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,36 @@ func (c *client) CreateService(ctx context.Context, service types.Service) (*typ
return output.Service, nil
}

func (c *client) PruneServiceTasks(ctx context.Context, service types.Service) error {
input := &ecs.UpdateServiceInput{
Cluster: service.ClusterArn,
Service: service.ServiceName,
DesiredCount: aws.Int32(0),
}

_, err := c.ecsClient.UpdateService(ctx, input)
if err != nil {
return fmt.Errorf("failed to update ECS service %s: %w", *service.ServiceName, err)
}

return nil
}

func (c *client) UpdateService(ctx context.Context, service types.Service) (*types.Service, error) {
input := &ecs.UpdateServiceInput{
Cluster: service.ClusterArn,
Service: service.ServiceName,
DesiredCount: aws.Int32(service.DesiredCount),
EnableExecuteCommand: aws.Bool(service.EnableExecuteCommand),
PlacementStrategy: service.PlacementStrategy,
// TODO: Support update other properties of service.
// PlacementConstraints: service.PlacementConstraints,
}

// If desiredCount is 0 or not set, keep current desiredCount because a user might use AutoScaling.
if service.DesiredCount != 0 {
input.DesiredCount = aws.Int32(service.DesiredCount)
}

output, err := c.ecsClient.UpdateService(ctx, input)
if err != nil {
return nil, fmt.Errorf("failed to update ECS service %s: %w", *service.ServiceName, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/app/piped/platformprovider/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ECS interface {
ServiceExists(ctx context.Context, clusterName string, servicesName string) (bool, error)
CreateService(ctx context.Context, service types.Service) (*types.Service, error)
UpdateService(ctx context.Context, service types.Service) (*types.Service, error)
PruneServiceTasks(ctx context.Context, service types.Service) error
WaitServiceStable(ctx context.Context, service types.Service) error
RegisterTaskDefinition(ctx context.Context, taskDefinition types.TaskDefinition) (*types.TaskDefinition, error)
RunTask(ctx context.Context, taskDefinition types.TaskDefinition, clusterArn string, launchType string, awsVpcConfiguration *config.ECSVpcConfiguration, tags []types.Tag) error
Expand Down