Skip to content

Commit 79443bb

Browse files
authored
Merge branch 'dev' into branch-eni-config
2 parents aea37e9 + c6101bc commit 79443bb

33 files changed

+692
-158
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
# 1.89.1
4+
* Changes included from discarded v1.89.0 release
5+
6+
# 1.89.0
7+
* Enhancement - Bump google.golang.org/grpc from 1.64.0 to 1.64.1 in /ecs-agent/daemonimages/csidriver [#4361](https://github.com/aws/amazon-ecs-agent/pull/4361)
8+
* Enhancement - Log unresolved dependencies at info level [#4419](https://github.com/aws/amazon-ecs-agent/pull/4419)
9+
* Enhancement - Make the path to resolv.conf a configuration parameter instead of a hardcoded string [#4421](https://github.com/aws/amazon-ecs-agent/pull/4421)
10+
* Bugfix - Implement reference counting of volume mounts in amazon-ecs-volume-plugin [#4425](https://github.com/aws/amazon-ecs-agent/pull/4425)
11+
* Bugfix - Set firelens mem_buf_limit by default [#4405](https://github.com/aws/amazon-ecs-agent/pull/4405)
12+
313
# 1.88.0
414
* Feature - Fault Injection Service Integration [#4414](https://github.com/aws/amazon-ecs-agent/pull/4414)
515
* Bugfix - Retry GPU devices check during env vars load if instance supports GPU [#4387](https://github.com/aws/amazon-ecs-agent/pull/4387)

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ else
3030
GO_VERSION=$(shell cat ./GO_VERSION)
3131
endif
3232

33-
VERSION=$(shell cat VERSION)
34-
3533
export GO111MODULE=auto
3634

3735
all: docker
@@ -401,6 +399,7 @@ get-deps-init:
401399
GO111MODULE=on go install honnef.co/go/tools/cmd/[email protected]
402400

403401
amazon-linux-sources.tgz:
402+
./scripts/update-version.sh
404403
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
405404
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
406405
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
@@ -411,14 +410,15 @@ amazon-linux-sources.tgz:
411410

412411
.amazon-linux-rpm-integrated-done: amazon-linux-sources.tgz
413412
test -e SOURCES || ln -s . SOURCES
414-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec
413+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
415414
find RPMS/ -type f -exec cp {} . \;
416415
touch .amazon-linux-rpm-integrated-done
417416

418417
amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
419418

420419
# Make target for Amazon Linux Codebuild jobs
421420
.amazon-linux-rpm-codebuild-done: get-cni-sources
421+
./scripts/update-version.sh
422422
cp packaging/amazon-linux-ami-integrated/ecs-agent.spec ecs-agent.spec
423423
cp packaging/amazon-linux-ami-integrated/ecs.conf ecs.conf
424424
cp packaging/amazon-linux-ami-integrated/ecs.service ecs.service
@@ -427,27 +427,31 @@ amazon-linux-rpm-integrated: .amazon-linux-rpm-integrated-done
427427
cp packaging/amazon-linux-ami-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
428428
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
429429
test -e SOURCES || ln -s . SOURCES
430-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb ecs-agent.spec
430+
rpmbuild --define "%_topdir $(PWD)" -bb ecs-agent.spec
431431
find RPMS/ -type f -exec cp {} . \;
432432
touch .amazon-linux-rpm-codebuild-done
433433

434434
amazon-linux-rpm-codebuild: .amazon-linux-rpm-codebuild-done
435435

436436
.generic-rpm-integrated-done: get-cni-sources
437+
./scripts/update-version.sh
437438
cp packaging/generic-rpm-integrated/amazon-ecs-init.spec amazon-ecs-init.spec
438439
cp packaging/generic-rpm-integrated/ecs.service ecs.service
439440
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.service amazon-ecs-volume-plugin.service
440441
cp packaging/generic-rpm-integrated/amazon-ecs-volume-plugin.socket amazon-ecs-volume-plugin.socket
441442
tar -czf ./sources.tgz ecs-init scripts misc agent amazon-ecs-cni-plugins amazon-vpc-cni-plugins agent-container Makefile VERSION GO_VERSION
442443
test -e SOURCES || ln -s . SOURCES
443-
rpmbuild --define "%version ${VERSION}" --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
444+
rpmbuild --define "%_topdir $(PWD)" -bb amazon-ecs-init.spec
444445
find RPMS/ -type f -exec cp {} . \;
445446
touch .generic-rpm-integrated-done
446447

447448
# Build init rpm
448449
generic-rpm-integrated: .generic-rpm-integrated-done
449450

451+
VERSION = $(shell cat ecs-init/ECSVERSION)
452+
450453
.generic-deb-integrated-done: get-cni-sources
454+
./scripts/update-version.sh
451455
mkdir -p BUILDROOT
452456
tar -czf ./amazon-ecs-init_${VERSION}.orig.tar.gz ecs-init scripts README.md
453457
cp -r packaging/generic-deb-integrated/debian Makefile ecs-init scripts misc agent agent-container amazon-ecs-cni-plugins amazon-vpc-cni-plugins README.md VERSION GO_VERSION BUILDROOT

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.88.0
1+
1.89.1

agent/api/container/container.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,27 @@ func (c *Container) GetNetworkModeFromHostConfig() string {
12721272
return hostConfig.NetworkMode.NetworkName()
12731273
}
12741274

1275+
// GetMemoryReservationFromHostConfig returns the container memory reservation
1276+
func (c *Container) GetMemoryReservationFromHostConfig() int64 {
1277+
c.lock.RLock()
1278+
defer c.lock.RUnlock()
1279+
1280+
if c.DockerConfig.HostConfig == nil {
1281+
return 0
1282+
}
1283+
1284+
hostConfig := &dockercontainer.HostConfig{}
1285+
err := json.Unmarshal([]byte(*c.DockerConfig.HostConfig), hostConfig)
1286+
if err != nil {
1287+
seelog.Warnf("Encountered error when trying to get memory reservation for container %s: %v", c.RuntimeID, err)
1288+
return 0
1289+
}
1290+
1291+
// Soft limit is specified in MiB units but translated to bytes while being transferred to Agent
1292+
// Converting back to MiB
1293+
return hostConfig.MemoryReservation / (1024 * 1024)
1294+
}
1295+
12751296
// GetHostConfig returns the container's host config.
12761297
func (c *Container) GetHostConfig() *string {
12771298
c.lock.RLock()

agent/api/container/container_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,48 @@ func TestGetNetworkModeFromHostConfig(t *testing.T) {
751751
}
752752
}
753753

754+
func TestGetMemoryReservationFromHostConfig(t *testing.T) {
755+
getContainer := func(hostConfig *string) *Container {
756+
c := &Container{
757+
Name: "c",
758+
}
759+
c.DockerConfig.HostConfig = hostConfig
760+
return c
761+
}
762+
763+
getStrPtr := func(s string) *string {
764+
return &s
765+
}
766+
767+
testCases := []struct {
768+
name string
769+
container *Container
770+
expectedOutput int64
771+
}{
772+
{
773+
name: "happy case",
774+
container: getContainer(getStrPtr("{\"MemoryReservation\":268435456}")),
775+
expectedOutput: 256,
776+
},
777+
{
778+
name: "invalid case",
779+
container: getContainer(getStrPtr("invalid")),
780+
expectedOutput: 0,
781+
},
782+
{
783+
name: "nil case",
784+
container: getContainer(nil),
785+
expectedOutput: 0,
786+
},
787+
}
788+
789+
for _, tc := range testCases {
790+
t.Run(tc.name, func(t *testing.T) {
791+
assert.Equal(t, tc.expectedOutput, tc.container.GetMemoryReservationFromHostConfig())
792+
})
793+
}
794+
}
795+
754796
func TestShouldCreateWithEnvfiles(t *testing.T) {
755797
cases := []struct {
756798
in Container

agent/api/task/task.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ func (task *Task) initializeFirelensResource(config *config.Config, resourceFiel
12461246

12471247
for _, container := range task.Containers {
12481248
firelensConfig := container.GetFirelensConfig()
1249-
if firelensConfig != nil {
1249+
if firelensConfig != nil { // is Firelens container
12501250
var ec2InstanceID string
12511251
if container.Environment != nil && container.Environment[awsExecutionEnvKey] == ec2ExecutionEnv {
12521252
ec2InstanceID = resourceFields.EC2InstanceID
@@ -1260,9 +1260,22 @@ func (task *Task) initializeFirelensResource(config *config.Config, resourceFiel
12601260
} else {
12611261
networkMode = container.GetNetworkModeFromHostConfig()
12621262
}
1263+
// Resolve Firelens container memory limit to be used for calculating Firelens memory buffer limit
1264+
// We will use the container 'memoryReservation' (soft limit) if present, otherwise the container 'memory' (hard limit)
1265+
// If neither is present, we will pass in 0 indicating that a memory limit is not specified, and firelens will
1266+
// fall back to use a default memory buffer limit value
1267+
// see - agent/taskresource/firelens/firelensconfig_unix.go:resolveMemBufLimit()
1268+
var containerMemoryLimit int64
1269+
if memoryReservation := container.GetMemoryReservationFromHostConfig(); memoryReservation > 0 {
1270+
containerMemoryLimit = memoryReservation
1271+
} else if container.Memory > 0 {
1272+
containerMemoryLimit = int64(container.Memory)
1273+
} else {
1274+
containerMemoryLimit = 0
1275+
}
12631276
firelensResource, err := firelens.NewFirelensResource(config.Cluster, task.Arn, task.Family+":"+task.Version,
12641277
ec2InstanceID, config.DataDir, firelensConfig.Type, config.AWSRegion, networkMode, firelensConfig.Options, containerToLogOptions,
1265-
credentialsManager, task.ExecutionCredentialsID)
1278+
credentialsManager, task.ExecutionCredentialsID, containerMemoryLimit)
12661279
if err != nil {
12671280
return errors.Wrap(err, "unable to initialize firelens resource")
12681281
}

agent/taskresource/firelens/firelens_unimplemented.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type FirelensResource struct{}
5353
// NewFirelensResource returns a new FirelensResource.
5454
func NewFirelensResource(cluster, taskARN, taskDefinition, ec2InstanceID, dataDir, firelensConfigType, region, networkMode string,
5555
firelensOptions map[string]string, containerToLogOptions map[string]map[string]string, credentialsManager credentials.Manager,
56-
executionCredentialsID string) (*FirelensResource, error) {
56+
executionCredentialsID string, containerMemoryLimit int64) (*FirelensResource, error) {
5757
return nil, errors.New("not implemented")
5858
}
5959

agent/taskresource/firelens/firelens_unix.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type FirelensResource struct {
8383
networkMode string
8484
ioutil ioutilwrapper.IOUtil
8585
s3ClientCreator factory.S3ClientCreator
86+
containerMemoryLimit int64
8687

8788
// Fields for the common functionality of task resource. Access to these fields are protected by lock.
8889
createdAtUnsafe time.Time
@@ -98,7 +99,7 @@ type FirelensResource struct {
9899
// NewFirelensResource returns a new FirelensResource.
99100
func NewFirelensResource(cluster, taskARN, taskDefinition, ec2InstanceID, dataDir, firelensConfigType, region, networkMode string,
100101
firelensOptions map[string]string, containerToLogOptions map[string]map[string]string, credentialsManager credentials.Manager,
101-
executionCredentialsID string) (*FirelensResource, error) {
102+
executionCredentialsID string, containerMemoryLimit int64) (*FirelensResource, error) {
102103
firelensResource := &FirelensResource{
103104
cluster: cluster,
104105
taskARN: taskARN,
@@ -112,6 +113,7 @@ func NewFirelensResource(cluster, taskARN, taskDefinition, ec2InstanceID, dataDi
112113
s3ClientCreator: factory.NewS3ClientCreator(),
113114
executionCredentialsID: executionCredentialsID,
114115
credentialsManager: credentialsManager,
116+
containerMemoryLimit: containerMemoryLimit,
115117
}
116118

117119
fields := strings.Split(taskARN, "/")

0 commit comments

Comments
 (0)