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

Add support for docker storage options #4908

Merged
merged 2 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ var (
"readonly_rootfs": hclspec.NewAttr("readonly_rootfs", "bool", false),
"security_opt": hclspec.NewAttr("security_opt", "list(string)", false),
"shm_size": hclspec.NewAttr("shm_size", "number", false),
"storage_opt": hclspec.NewBlockAttrs("storage_opt", "string", false),
"sysctl": hclspec.NewBlockAttrs("sysctl", "string", false),
"tty": hclspec.NewAttr("tty", "bool", false),
"ulimit": hclspec.NewBlockAttrs("ulimit", "string", false),
Expand Down Expand Up @@ -319,6 +320,7 @@ type TaskConfig struct {
ReadonlyRootfs bool `codec:"readonly_rootfs"`
SecurityOpt []string `codec:"security_opt"`
ShmSize int64 `codec:"shm_size"`
StorageOpt map[string]string `codec:"storage_opt"`
Sysctl map[string]string `codec:"sysctl"`
TTY bool `codec:"tty"`
Ulimit map[string]string `codec:"ulimit"`
Expand Down
1 change: 1 addition & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
// used to share data between different tasks in the same task group.
Binds: binds,

StorageOpt: driverConfig.StorageOpt,
VolumeDriver: driverConfig.VolumeDriver,

PidsLimit: driverConfig.PidsLimit,
Expand Down
19 changes: 19 additions & 0 deletions drivers/docker/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,25 @@ func TestDockerDriver_SecurityOpt(t *testing.T) {
require.Exactly(t, cfg.SecurityOpt, container.HostConfig.SecurityOpt)
}

func TestDockerDriver_CreateContainerConfig(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Since the point of this test is to specifically test the storage_opt field I would vote for appending _StorageOpt to the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intend for this test to be generic for all options we add in future (e.g. tmpfs options) - I simply started with image and storage opt, but I can add more as well.

t.Parallel()

task, cfg, _ := dockerTask(t)
opt := map[string]string{"size": "120G"}

cfg.StorageOpt = opt
require.NoError(t, task.EncodeConcreteDriverConfig(cfg))

dh := dockerDriverHarness(t, nil)
driver := dh.Impl().(*Driver)

c, err := driver.createContainerConfig(task, cfg, "org/repo:0.1")
require.NoError(t, err)

require.Equal(t, "org/repo:0.1", c.Config.Image)
require.EqualValues(t, opt, c.HostConfig.StorageOpt)
}

func TestDockerDriver_Capabilities(t *testing.T) {
if !tu.IsTravis() {
t.Parallel()
Expand Down
13 changes: 13 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ The `docker` driver supports the following configuration in the job spec. Only

* `shm_size` - (Optional) The size (bytes) of /dev/shm for the container.

* `storage_opt` - (Optional) A key-value map of storage options set to the containers on start.
This overrides the [host dockerd configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#options-per-storage-driver).
For example:


```hcl
config {
storage_opt = {
size = "40G"
}
}
```

* `SSL` - (Optional) If this is set to true, Nomad uses SSL to talk to the
repository. The default value is `true`. **Deprecated as of 0.5.3**

Expand Down