Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Docker Pids Limit #4341

Merged
merged 3 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions client/driver/docker_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"

tu "github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -39,3 +42,57 @@ func TestDockerDriver_authFromHelper(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []byte("https://registry.local:5000"), content)
}

func TestDockerDriver_PidsLimit(t *testing.T) {
if !tu.IsTravis() {
t.Parallel()
}
if !testutil.DockerIsConnected(t) {
t.Skip("Docker not connected")
}

task, _, _ := dockerTask(t)
task.Config["pids_limit"] = "1"
task.Config["command"] = "/bin/sh"
task.Config["args"] = []string{"-c", "sleep 2 & sleep 2"}

ctx := testDockerDriverContexts(t, task)
defer ctx.AllocDir.Destroy()
d := NewDockerDriver(ctx.DriverCtx)

// Copy the image into the task's directory
copyImage(t, ctx.ExecCtx.TaskDir, "busybox.tar")

_, err := d.Prestart(ctx.ExecCtx, task)
if err != nil {
t.Fatalf("error in prestart: %v", err)
}
resp, err := d.Start(ctx.ExecCtx, task)
if err != nil {
t.Fatalf("err: %v", err)
}
defer resp.Handle.Kill()

select {
case res := <-resp.Handle.WaitCh():
if res.Successful() {
t.Fatalf("expected error, but container exited successful")
}
case <-time.After(time.Duration(tu.TestMultiplier()*5) * time.Second):
t.Fatalf("timeout")
}

// XXX Logging doesn't work on OSX so just test on Linux
// Check that data was written to the directory.
outputFile := filepath.Join(ctx.ExecCtx.TaskDir.LogDir, "redis-demo.stderr.0")
act, err := ioutil.ReadFile(outputFile)
if err != nil {
t.Fatalf("Couldn't read expected output: %v", err)
}

exp := "can't fork"
if !strings.Contains(string(act), exp) {
t.Fatalf("Expected failed fork: %q", act)
}

}
3 changes: 3 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ The `docker` driver supports the following configuration in the job spec. Only
* `readonly_rootfs` - (Optional) `true` or `false` (default). Mount
the container's filesystem as read only.

* `pids_limit` - (Optional) An integer value that specifies the pid limit for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be just pid_limit (singular vs plural)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker run calls it pids-limit https://docs.docker.com/engine/reference/commandline/run/ so would prefer to keep it the same for consistency

the container. Defaults to unlimited.

### Container Name

Nomad creates a container after pulling an image. Containers are named
Expand Down