Skip to content

Commit

Permalink
Support Canary for ECS without ELB or target groups (#4690)
Browse files Browse the repository at this point in the history
* Support ECS CanaryRollout without TargetGroups

Signed-off-by: t-kikuc <[email protected]>

* Support ECS PrimaryRollout without TargetGroups

Signed-off-by: t-kikuc <[email protected]>

* Refuse ECS TrafficRouting stage for ServiceDiscovery

Signed-off-by: t-kikuc <[email protected]>

* Add a comment for ECS Rollback for ServiceDiscovery

Signed-off-by: t-kikuc <[email protected]>

* Add comments

Signed-off-by: t-kikuc <[email protected]>

* Removed unnecessary comments

Signed-off-by: t-kikuc <[email protected]>

---------

Signed-off-by: t-kikuc <[email protected]>
Co-authored-by: Khanh Tran <[email protected]>
  • Loading branch information
t-kikuc and khanhtc1202 authored Dec 1, 2023
1 parent e5d7b4b commit d12bf7d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
64 changes: 46 additions & 18 deletions pkg/app/piped/executor/ecs/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,27 @@ func (e *deployExecutor) ensurePrimaryRollout(ctx context.Context) model.StageSt
return model.StageStatus_STAGE_FAILURE
}

primary, _, ok := loadTargetGroups(&e.Input, e.appCfg, e.deploySource)
if !ok {
return model.StageStatus_STAGE_FAILURE
}
if primary == nil {
e.LogPersister.Error("Primary target group is required to enable rolling out PRIMARY variant")
return model.StageStatus_STAGE_FAILURE
}
switch e.appCfg.Input.AccessType {
case config.AccessTypeELB:
primary, _, ok := loadTargetGroups(&e.Input, e.appCfg, e.deploySource)
if !ok {
return model.StageStatus_STAGE_FAILURE
}
if primary == nil {
e.LogPersister.Error("Primary target group is required to enable rolling out PRIMARY variant")
return model.StageStatus_STAGE_FAILURE
}

if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, primary) {
if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, primary) {
return model.StageStatus_STAGE_FAILURE
}
case config.AccessTypeServiceDiscovery:
// Target groups are not used.
if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, nil) {
return model.StageStatus_STAGE_FAILURE
}
default:
e.LogPersister.Errorf("Unsupported access type %s in stage %s for ECS application", e.appCfg.Input.AccessType, e.Stage.Name)
return model.StageStatus_STAGE_FAILURE
}

Expand All @@ -152,23 +163,40 @@ func (e *deployExecutor) ensureCanaryRollout(ctx context.Context) model.StageSta
return model.StageStatus_STAGE_FAILURE
}

_, canary, ok := loadTargetGroups(&e.Input, e.appCfg, e.deploySource)
if !ok {
return model.StageStatus_STAGE_FAILURE
}
if canary == nil {
e.LogPersister.Error("Canary target group is required to enable rolling out CANARY variant")
return model.StageStatus_STAGE_FAILURE
}
switch e.appCfg.Input.AccessType {
case config.AccessTypeELB:
_, canary, ok := loadTargetGroups(&e.Input, e.appCfg, e.deploySource)
if !ok {
return model.StageStatus_STAGE_FAILURE
}
if canary == nil {
e.LogPersister.Error("Canary target group is required to enable rolling out CANARY variant")
return model.StageStatus_STAGE_FAILURE
}

if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, canary) {
if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, canary) {
return model.StageStatus_STAGE_FAILURE
}
case config.AccessTypeServiceDiscovery:
// Target groups are not used.
if !rollout(ctx, &e.Input, e.platformProviderName, e.platformProviderCfg, taskDefinition, servicedefinition, nil) {
return model.StageStatus_STAGE_FAILURE
}
default:
e.LogPersister.Errorf("Unsupported access type %s in stage %s for ECS application", e.appCfg.Input.AccessType, e.Stage.Name)
return model.StageStatus_STAGE_FAILURE
}

return model.StageStatus_STAGE_SUCCESS
}

func (e *deployExecutor) ensureTrafficRouting(ctx context.Context) model.StageStatus {
// Traffic Routing is not supported for other kinds than ELB.
if !e.appCfg.Input.IsAccessedViaELB() {
e.LogPersister.Errorf("Unsupported access type %s in stage %s for ECS application", e.appCfg.Input.AccessType, e.Stage.Name)
return model.StageStatus_STAGE_FAILURE
}

primary, canary, ok := loadTargetGroups(&e.Input, e.appCfg, e.deploySource)
if !ok {
return model.StageStatus_STAGE_FAILURE
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ func createPrimaryTaskSet(ctx context.Context, client provider.Client, service t
}

// Remove old taskSets if existed.
// HACK: All old task sets including canary are deleted here.
// However, we need to discuss whether we should delete the canary here or in later stage(CanaryClean).
for _, prevTaskSet := range prevTaskSets {
if err = client.DeleteTaskSet(ctx, *prevTaskSet); err != nil {
return err
Expand Down

0 comments on commit d12bf7d

Please sign in to comment.