Skip to content

Commit

Permalink
applied
Browse files Browse the repository at this point in the history
Signed-off-by: HoangNguyen689 <[email protected]>
  • Loading branch information
HoangNguyen689 committed Nov 19, 2024
1 parent 2f46b83 commit 930b46f
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions pkg/app/piped/driftdetector/ecs/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
// - taskDefinition.ContainerDefinitions[].PortMappings[].HostPort
//
// TODO: Maybe we should check diff of following fields when not set in the head manifests in some way. Currently they are ignored:
// - service.DeploymentConfiguration
// - service.PlatformVersion
// - service.RoleArn
func ignoreParameters(liveManifests provider.ECSManifests, headManifests provider.ECSManifests) (live, head provider.ECSManifests) {
Expand All @@ -262,10 +263,7 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
liveTask.Revision = 0 // TODO: Find a way to compare the revision if possible.
liveTask.TaskDefinitionArn = nil
for i := range liveTask.ContainerDefinitions {
// Sort the live environment variables by name.
envs := slices.Clone(liveTask.ContainerDefinitions[i].Environment)
envs = sortKeyPairs(envs)
liveTask.ContainerDefinitions[i].Environment = envs
liveTask.ContainerDefinitions[i].Environment = sortKeyPairs(liveTask.ContainerDefinitions[i].Environment)

for j := range liveTask.ContainerDefinitions[i].PortMappings {
// We ignore diff of HostPort because it has several default values. See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html#ECS-Type-ContainerDefinition-portMappings.
Expand Down Expand Up @@ -305,7 +303,6 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
liveService.NetworkConfiguration = &types.NetworkConfiguration{AwsvpcConfiguration: &awsvpcCfg}
}

// Ignore the diff of DeploymentConfiguration if it's not specified.
if headService.DeploymentConfiguration == nil {
liveService.DeploymentConfiguration = nil
}
Expand All @@ -328,10 +325,7 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
cd.Essential = aws.Bool(true)
}

// Sort the head environment variables by name.
envs := slices.Clone(cd.Environment)
envs = sortKeyPairs(envs)
cd.Environment = envs
cd.Environment = sortKeyPairs(cd.Environment)

cd.PortMappings = slices.Clone(cd.PortMappings)
for j := range cd.PortMappings {
Expand Down Expand Up @@ -499,8 +493,7 @@ func ignoreAutoScalingDiff(r *provider.DiffResult) bool {
}

func sortKeyPairs(kps []types.KeyValuePair) []types.KeyValuePair {
sorted := make([]types.KeyValuePair, len(kps))
copy(sorted, kps)
sorted := slices.Clone(kps)
sort.Slice(sorted, func(i, j int) bool {
return *sorted[i].Name < *sorted[j].Name
})
Expand Down

0 comments on commit 930b46f

Please sign in to comment.