Skip to content

Commit 7411b59

Browse files
committed
Add ulimits to parseV3
1 parent 6e13bda commit 7411b59

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

ecs-cli/modules/cli/compose/project/project_parseV3.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ func convertToContainerConfig(serviceConfig types.ServiceConfig, serviceVols *ad
154154
}
155155
c.Tmpfs = ecsTmpfs
156156
}
157-
// TODO: reconcile with top-level Volumes key
157+
158+
if len(serviceConfig.Ulimits) > 0 {
159+
c.Ulimits = convertToECSUlimits(serviceConfig.Ulimits)
160+
}
161+
158162
if len(serviceConfig.Volumes) > 0 {
159163
mountPoints := []*ecs.MountPoint{}
160164

@@ -207,6 +211,25 @@ func convertPortConfigToECSMapping(portConfig types.ServicePortConfig) *ecs.Port
207211
return &ecsMapping
208212
}
209213

214+
func convertToECSUlimits(ulimits map[string]*types.UlimitsConfig) []*ecs.Ulimit {
215+
ecsUlimits := []*ecs.Ulimit{}
216+
217+
for name, ulimit := range ulimits {
218+
ecsULimit := ecs.Ulimit{}
219+
ecsULimit.SetName(name)
220+
221+
if ulimit.Single > 0 {
222+
ecsULimit.SetSoftLimit(int64(ulimit.Single))
223+
ecsULimit.SetHardLimit(int64(ulimit.Single))
224+
} else {
225+
ecsULimit.SetSoftLimit(int64(ulimit.Soft))
226+
ecsULimit.SetHardLimit(int64(ulimit.Hard))
227+
}
228+
ecsUlimits = append(ecsUlimits, &ecsULimit)
229+
}
230+
return ecsUlimits
231+
}
232+
210233
func logWarningForDeployFields(d types.DeployConfig, serviceName string) {
211234
if d.Resources.Limits != nil || d.Resources.Reservations != nil {
212235
log.WithFields(log.Fields{

ecs-cli/modules/cli/compose/project/project_parseV3_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ services:
4949
tmpfs:
5050
- "/run:rw,size=1gb"
5151
read_only: true
52+
ulimits:
53+
rss: 65535
54+
nofile:
55+
soft: 2000
56+
hard: 4000
57+
nice:
58+
soft: 300
59+
hard: 500
5260
mysql:
5361
image: mysql
5462
labels:
@@ -418,6 +426,19 @@ func verifyConvertToContainerConfigOutput(t *testing.T, expected types.ServiceCo
418426
assert.Empty(t, actual.PortMappings)
419427
}
420428

429+
if len(expected.Ulimits) > 0 {
430+
assert.Equal(t, len(expected.Ulimits), len(actual.Ulimits), "Expected number of Ulimits to match")
431+
432+
for _, lim := range actual.Ulimits {
433+
matchingServUlimit := expected.Ulimits[*lim.Name]
434+
435+
assert.NotNil(t, matchingServUlimit, "Expected ContainerConfig ulimit to have corresponding serviceConfig ulimit")
436+
verifyUlimit(t, *matchingServUlimit, *lim)
437+
}
438+
} else {
439+
assert.Empty(t, actual.Ulimits)
440+
}
441+
421442
if len(expected.Volumes) > 0 {
422443
for i, vol := range expected.Volumes {
423444
if vol.Type == "volume" {
@@ -437,6 +458,20 @@ func verifyConvertToContainerConfigOutput(t *testing.T, expected types.ServiceCo
437458
}
438459
}
439460

461+
func verifyUlimit(t *testing.T, servUlimit types.UlimitsConfig, containerUlimit ecs.Ulimit) {
462+
var soft int64
463+
var hard int64
464+
if servUlimit.Single > 0 {
465+
soft = int64(servUlimit.Single)
466+
hard = int64(servUlimit.Single)
467+
} else {
468+
soft = int64(servUlimit.Soft)
469+
hard = int64(servUlimit.Hard)
470+
}
471+
assert.Equal(t, soft, *containerUlimit.SoftLimit, "Expected soft limit to match")
472+
assert.Equal(t, hard, *containerUlimit.HardLimit, "Expected hard limit to match")
473+
}
474+
440475
func verifyMountPoint(t *testing.T, servVolume types.ServiceVolumeConfig, mountPoint ecs.MountPoint) {
441476
if servVolume.Source == "" {
442477
assert.True(t, strings.HasPrefix(*mountPoint.SourceVolume, "volume-"), "Expected volume Source to being with 'volume-'")

0 commit comments

Comments
 (0)