From cf0e6ca27ae389dfca6f18102d12821ca737aa0c Mon Sep 17 00:00:00 2001 From: Roberto Jimenez Sanchez Date: Mon, 24 Apr 2017 15:09:39 +0200 Subject: [PATCH 1/3] Add --limit-memory Signed-off-by: Steffen Uhlig --- .gitignore | 1 + commands/create.go | 20 +++++++++++++------- commands/properties.go | 4 ++++ test/create.bats | 9 +++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a6353d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.envrc diff --git a/commands/create.go b/commands/create.go index 23a0cc6..f63fe0b 100644 --- a/commands/create.go +++ b/commands/create.go @@ -9,13 +9,14 @@ import ( ) type Create struct { - Handle string `short:"n" long:"handle" description:"name to give container"` - RootFS string `short:"r" long:"rootfs" description:"rootfs image with which to create the container"` - Env []string `short:"e" long:"env" description:"set environment variables"` - Grace time.Duration `short:"g" long:"grace" description:"grace time (resetting ttl) of container"` - Privileged bool `short:"p" long:"privileged" description:"privileged user in the container is privileged in the host"` - Network string `long:"network" description:"the subnet of the container"` - BindMounts []string `short:"m" long:"bind-mount" description:"bind mount host-path:container-path"` + Handle string `short:"n" long:"handle" description:"name to give container"` + RootFS string `short:"r" long:"rootfs" description:"rootfs image with which to create the container"` + Env []string `short:"e" long:"env" description:"set environment variables"` + Grace time.Duration `short:"g" long:"grace" description:"grace time (resetting ttl) of container"` + Privileged bool `short:"p" long:"privileged" description:"privileged user in the container is privileged in the host"` + Network string `long:"network" description:"the subnet of the container"` + BindMounts []string `short:"m" long:"bind-mount" description:"bind mount host-path:container-path"` + LimitMemory uint64 `short:"k" long:"limit-memory" description:"limits the memory used by the container. Value in bytes"` } func (command *Create) Execute(args []string) error { @@ -43,6 +44,11 @@ func (command *Create) Execute(args []string) error { Env: command.Env, Network: command.Network, BindMounts: bindMounts, + Limits: garden.Limits{ + Memory: garden.MemoryLimits{ + LimitInBytes: command.LimitMemory, + }, + }, }) failIf(err) diff --git a/commands/properties.go b/commands/properties.go index ba3530d..eda50cb 100644 --- a/commands/properties.go +++ b/commands/properties.go @@ -17,6 +17,9 @@ func (command *Properties) Execute(maybeHandle []string) error { properties, err := container.Properties() failIf(err) + memoryLimits, err := container.CurrentMemoryLimits() + failIf(err) + if command.AsJSON { toPrint, err := json.MarshalIndent(properties, "", " ") failIf(err) @@ -25,6 +28,7 @@ func (command *Properties) Execute(maybeHandle []string) error { for k, v := range properties { fmt.Printf("%s\t%s\n", k, v) } + fmt.Printf("memory.limit\t%d bytes\n", memoryLimits.LimitInBytes) } return nil diff --git a/test/create.bats b/test/create.bats index 25981f3..f6301e6 100755 --- a/test/create.bats +++ b/test/create.bats @@ -11,6 +11,15 @@ load test_helper assert_match $handle } +@test "a container can be created with memory limits" { + handle=$(gaol create --limit-memory 52428800) + assert_success + + run gaol properties $handle + assert_success + assert_match "memory.limit\t52428800 bytes" +} + @test "a created container can have its handle chosen" { run gaol create -n awesome-handle From 2b64b585539dc0af705a38e13d9c333477ae8e93 Mon Sep 17 00:00:00 2001 From: Steffen Uhlig Date: Mon, 24 Apr 2017 16:19:58 +0200 Subject: [PATCH 2/3] Add test for reporting memory limit through properties Signed-off-by: Roberto Jimenez Sanchez --- test/properties.bats | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/properties.bats diff --git a/test/properties.bats b/test/properties.bats new file mode 100644 index 0000000..7a526fb --- /dev/null +++ b/test/properties.bats @@ -0,0 +1,9 @@ +#!/usr/bin/env bats + +load test_helper + +@test "a container reports its limits" { + run gaol properties $(gaol create) + assert_success + assert_match "memory.limit\t0 bytes" +} From 8df5365e9924cad147bddbf4775c8f2505145d6f Mon Sep 17 00:00:00 2001 From: Roberto Jimenez Sanchez Date: Mon, 24 Apr 2017 17:10:42 +0200 Subject: [PATCH 3/3] Report the output folder instead of opening it Makes the build a little less obstrusive. Signed-off-by: Steffen Uhlig --- scripts/build | 2 +- test/create.bats | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build b/scripts/build index 47d25e4..d8a2ff3 100755 --- a/scripts/build +++ b/scripts/build @@ -8,4 +8,4 @@ for platform in linux darwin; do go build -o ${workspace}/gaol_${platform} github.com/contraband/gaol done -open ${workspace} +echo Output is in "${workspace}" diff --git a/test/create.bats b/test/create.bats index f6301e6..fb3718b 100755 --- a/test/create.bats +++ b/test/create.bats @@ -31,4 +31,3 @@ load test_helper assert_success assert_match $handle } -