Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 221aecf

Browse files
committed
Add mem_reservation tests (and to schema v1)
Signed-off-by: Lachlan Donald <[email protected]>
1 parent 06b5971 commit 221aecf

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

config/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ var schemaDataV1 = `{
8686
"log_opt": {"type": "object"},
8787
"mac_address": {"type": "string"},
8888
"mem_limit": {"type": ["number", "string"]},
89+
"mem_reservation": {"type": ["number", "string"]},
8990
"memswap_limit": {"type": ["number", "string"]},
9091
"mem_swappiness": {"type": "integer"},
9192
"net": {"type": "string"},

docker/service/convert.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,17 @@ func Convert(c *config.ServiceConfig, ctx project.Context, clientFactory compose
184184
memorySwappiness := int64(c.MemSwappiness)
185185

186186
resources := container.Resources{
187-
CgroupParent: c.CgroupParent,
188-
Memory: int64(c.MemLimit),
189-
MemorySwap: int64(c.MemSwapLimit),
190-
MemorySwappiness: &memorySwappiness,
191-
CPUShares: int64(c.CPUShares),
192-
CPUQuota: int64(c.CPUQuota),
193-
CpusetCpus: c.CPUSet,
194-
Ulimits: ulimits,
195-
Devices: deviceMappings,
196-
OomKillDisable: &c.OomKillDisable,
187+
CgroupParent: c.CgroupParent,
188+
Memory: int64(c.MemLimit),
189+
MemoryReservation: int64(c.MemReservation),
190+
MemorySwap: int64(c.MemSwapLimit),
191+
MemorySwappiness: &memorySwappiness,
192+
CPUShares: int64(c.CPUShares),
193+
CPUQuota: int64(c.CPUQuota),
194+
CpusetCpus: c.CPUSet,
195+
Ulimits: ulimits,
196+
Devices: deviceMappings,
197+
OomKillDisable: &c.OomKillDisable,
197198
}
198199

199200
networkMode := c.NetworkMode

docker/service/convert_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ func TestMemSwappiness(t *testing.T) {
138138
assert.Equal(t, int64(10), *hostCfg.MemorySwappiness)
139139
}
140140

141+
func TestMemReservation(t *testing.T) {
142+
ctx := &ctx.Context{}
143+
sc := &config.ServiceConfig{
144+
MemReservation: 100000,
145+
}
146+
_, hostCfg, err := Convert(sc, ctx.Context, nil)
147+
assert.Nil(t, err)
148+
149+
assert.Equal(t, int64(100000), hostCfg.MemoryReservation)
150+
}
151+
141152
func TestOomKillDisable(t *testing.T) {
142153
ctx := &ctx.Context{}
143154
sc := &config.ServiceConfig{

0 commit comments

Comments
 (0)