Skip to content

Commit af2d227

Browse files
github-actions[bot]HoangNguyen689ffjlabo
authored
Cherry-pick #5344 #5351 (#5352)
* Handle ECS Apps DeploymentConfiguration and containers Environments drift detection (#5344) * Handle ECS Apps DeploymentConfiguration and containers Environments driff detection Signed-off-by: HoangNguyen689 <[email protected]> * applied Signed-off-by: HoangNguyen689 <[email protected]> --------- Signed-off-by: HoangNguyen689 <[email protected]> Signed-off-by: pipecd-bot <[email protected]> * Update RELEASE to v0.49.4 (#5351) Signed-off-by: Yoshiki Fujikane <[email protected]> Signed-off-by: pipecd-bot <[email protected]> --------- Signed-off-by: HoangNguyen689 <[email protected]> Signed-off-by: pipecd-bot <[email protected]> Signed-off-by: Yoshiki Fujikane <[email protected]> Co-authored-by: HoangNguyen689 <[email protected]> Co-authored-by: Yoshiki Fujikane <[email protected]>
1 parent 7bbc4d5 commit af2d227

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by `make release` command.
22
# DO NOT EDIT.
3-
tag: v0.49.3
3+
tag: v0.49.4
44

55
releaseNoteGenerator:
66
showCommitter: false

pkg/app/piped/driftdetector/ecs/detector.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"path/filepath"
2222
"slices"
23+
"sort"
2324
"strings"
2425
"time"
2526

@@ -235,6 +236,7 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
235236
// - taskDefinition.ContainerDefinitions[].PortMappings[].HostPort
236237
//
237238
// TODO: Maybe we should check diff of following fields when not set in the head manifests in some way. Currently they are ignored:
239+
// - service.DeploymentConfiguration
238240
// - service.PlatformVersion
239241
// - service.RoleArn
240242
func ignoreParameters(liveManifests provider.ECSManifests, headManifests provider.ECSManifests) (live, head provider.ECSManifests) {
@@ -261,6 +263,8 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
261263
liveTask.Revision = 0 // TODO: Find a way to compare the revision if possible.
262264
liveTask.TaskDefinitionArn = nil
263265
for i := range liveTask.ContainerDefinitions {
266+
liveTask.ContainerDefinitions[i].Environment = sortKeyPairs(liveTask.ContainerDefinitions[i].Environment)
267+
264268
for j := range liveTask.ContainerDefinitions[i].PortMappings {
265269
// 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.
266270
liveTask.ContainerDefinitions[i].PortMappings[j].HostPort = nil
@@ -299,6 +303,10 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
299303
liveService.NetworkConfiguration = &types.NetworkConfiguration{AwsvpcConfiguration: &awsvpcCfg}
300304
}
301305

306+
if headService.DeploymentConfiguration == nil {
307+
liveService.DeploymentConfiguration = nil
308+
}
309+
302310
// TODO: In order to check diff of the tags, we need to add pipecd-managed tags and sort.
303311
liveService.Tags = nil
304312
headService.Tags = nil
@@ -316,6 +324,9 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
316324
// Essential is true by default. See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html#ECS-Type-ContainerDefinition-es.
317325
cd.Essential = aws.Bool(true)
318326
}
327+
328+
cd.Environment = sortKeyPairs(cd.Environment)
329+
319330
cd.PortMappings = slices.Clone(cd.PortMappings)
320331
for j := range cd.PortMappings {
321332
pm := &cd.PortMappings[j]
@@ -480,3 +491,12 @@ func ignoreAutoScalingDiff(r *provider.DiffResult) bool {
480491
r.New.ServiceDefinition.DesiredCount == 0 && // When desiredCount is 0 or not defined in the head manifest, autoscaling may be enabled.
481492
r.Old.ServiceDefinition.DesiredCount != r.New.ServiceDefinition.DesiredCount
482493
}
494+
495+
func sortKeyPairs(kps []types.KeyValuePair) []types.KeyValuePair {
496+
sorted := slices.Clone(kps)
497+
sort.Slice(sorted, func(i, j int) bool {
498+
return *sorted[i].Name < *sorted[j].Name
499+
})
500+
501+
return sorted
502+
}

pkg/app/piped/driftdetector/ecs/detector_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func TestIgnoreParameters(t *testing.T) {
4949
SecurityGroups: []string{"1_test-sg", "0_test-sg"},
5050
},
5151
},
52+
DeploymentConfiguration: &types.DeploymentConfiguration{
53+
MaximumPercent: aws.Int32(200),
54+
MinimumHealthyPercent: aws.Int32(100),
55+
},
5256
PendingCount: 3,
5357
PlatformFamily: aws.String("LINUX"),
5458
PlatformVersion: aws.String("1.4"),
@@ -104,6 +108,16 @@ func TestIgnoreParameters(t *testing.T) {
104108
Protocol: types.TransportProtocolTcp,
105109
},
106110
},
111+
Environment: []types.KeyValuePair{
112+
{
113+
Name: aws.String("A-TEST-ENV"),
114+
Value: aws.String("a-test-value"),
115+
},
116+
{
117+
Name: aws.String("B-TEST-ENV"),
118+
Value: aws.String("b-test-value"),
119+
},
120+
},
107121
},
108122
{
109123
Essential: aws.Bool(true),
@@ -149,6 +163,16 @@ func TestIgnoreParameters(t *testing.T) {
149163
// Protocol will be automatically tcp
150164
{}, {},
151165
},
166+
Environment: []types.KeyValuePair{
167+
{
168+
Name: aws.String("B-TEST-ENV"),
169+
Value: aws.String("b-test-value"),
170+
},
171+
{
172+
Name: aws.String("A-TEST-ENV"),
173+
Value: aws.String("a-test-value"),
174+
},
175+
},
152176
},
153177
{
154178
// Use default value for 'Essential'

0 commit comments

Comments
 (0)