-
-
Save drscre/4b40668bb96081763f079085617e6056 to your computer and use it in GitHub Desktop.
Add "memory_mb" option to Nomad docker driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/client/driver/docker.go b/client/driver/docker.go | |
index 0dacbac..ca1fe20 100644 | |
--- a/client/driver/docker.go | |
+++ b/client/driver/docker.go | |
@@ -130,10 +130,11 @@ type DockerDriverConfig struct { | |
Interactive bool `mapstructure:"interactive"` // Keep STDIN open even if not attached | |
ShmSize int64 `mapstructure:"shm_size"` // Size of /dev/shm of the container in bytes | |
WorkDir string `mapstructure:"work_dir"` // Working directory inside the container | |
Logging []DockerLoggingOpts `mapstructure:"logging"` // Logging options for syslog server | |
Volumes []string `mapstructure:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container | |
+ MemoryMB int64 `mapstructure:"memory_mb"` // Hard memory limit for docker container: 0 - use value from resources, -1 - no limit | |
} | |
// Validate validates a docker driver config | |
func (c *DockerDriverConfig) Validate() error { | |
if c.ImageName == "" { | |
@@ -321,10 +322,13 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error { | |
Type: fields.TypeArray, | |
}, | |
"volumes": &fields.FieldSchema{ | |
Type: fields.TypeArray, | |
}, | |
+ "memory_mb": &fields.FieldSchema{ | |
+ Type: fields.TypeInt, | |
+ }, | |
}, | |
} | |
if err := fd.Validate(); err != nil { | |
return err | |
@@ -669,11 +673,18 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas | |
if driverConfig.WorkDir != "" { | |
config.WorkingDir = driverConfig.WorkDir | |
} | |
- memLimit := int64(task.Resources.MemoryMB) * 1024 * 1024 | |
+ var memLimit int64 | |
+ if driverConfig.MemoryMB == 0 { | |
+ memLimit = int64(task.Resources.MemoryMB) * 1024 * 1024 | |
+ } else if driverConfig.MemoryMB < 0 { | |
+ memLimit = 0 | |
+ } else { | |
+ memLimit = driverConfig.MemoryMB * 1024 * 1024 | |
+ } | |
if len(driverConfig.Logging) == 0 { | |
if runtime.GOOS != "darwin" { | |
d.logger.Printf("[DEBUG] driver.docker: Setting default logging options to syslog and %s", syslogAddr) | |
driverConfig.Logging = []DockerLoggingOpts{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment