hashicorp / hashicorp/nomad

docker driver: Allow shm_size (type: number) to accept human friendly inputs e.g. `512M`

Open
#10,879 2 comments 2 reactions 0 assignees View on GitHub
theme/driver/docker theme/jobspec type/enhancement
Dominant language
Go
Stars
17k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
105

Description

Nomad docker driver has an option [`shm_size`](https://www.nomadproject.io/docs/drivers/docker#shm_size) which allows to set `/dev/shm` for the container in `bytes`.

Currently, it is defined as a [`number`](https://github.com/hashicorp/nomad/blob/main/drivers/docker/config.go#L389) type and accept values in `bytes`. This is not very human friendly since if I have to set `512MB` I would need to set:

```
config {
shm_size = 536870912
}
```

We can change the `shm_size` type to `string` so it can accept human friendly inputs e.g. to set `shm_size` to `512MB` I can just do:

```
config {
shm_size = "512M"
}
```

We will have to do a [`units.RAMInBytes()`](https://github.com/docker/go-units/blob/master/size.go#L86) conversion call before setting [`HostConfig.ShmSize`](https://github.com/hashicorp/nomad/blob/main/drivers/docker/driver.go#L923) in docker driver.

The user can still pass `shm_size` in `bytes` e.g. `536870912` however, they will also be able to pass `shm_size` in human friendly format e.g. `512M`.

The change is small and I can open a quick PR right away. However, since this breaks backward compatibility by changing the `shm_size` type from `number` to `string`, I wanted to check first, if maintainers are okay with this?

Adding @tgross and @notnoop for inputs!

Contributor guide

No contributing guide indexed for this repository

Research direction

Read drivers/docker/config.go at the shm_size definition and drivers/docker/driver.go near HostConfig.ShmSize, then check the docker driver tests for existing configuration coverage. Confirm the compatibility decision, support the stated byte and human-friendly inputs through the docker units conversion, and add coverage showing both forms reach the expected shared-memory size.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
devops, infrastructure
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.