Skip to content

Commit

Permalink
Add support for memory_max setting
Browse files Browse the repository at this point in the history
Nomad 1.1.0 introduced a new memory_max setting enabling memory
over-subscription for tasks. This adds support for it.
  • Loading branch information
JanMa committed May 28, 2021
1 parent 5225749 commit 314f872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Support for new `memory_max` setting
### Changed
- Update to Nomad v1.1.0
- Lower log level of passed arguments to systemd-nspawn to DEBUG
Expand Down
5 changes: 5 additions & 0 deletions example/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ plugin "nspawn" {
enabled = true
}
}
server {
default_scheduler_config {
memory_oversubscription_enabled = true
}
}
13 changes: 9 additions & 4 deletions nspawn/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,13 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
driverConfig.Properties = make(hclutils.MapStrStr)
}

if cfg.Resources.LinuxResources != nil {
driverConfig.Properties["MemoryMax"] = strconv.Itoa(int(cfg.Resources.LinuxResources.MemoryLimitBytes))
if cfg.Resources.NomadResources != nil {
if cfg.Resources.NomadResources.Memory.MemoryMaxMB != 0 {
driverConfig.Properties["MemoryHigh"] = strconv.Itoa(int(cfg.Resources.NomadResources.Memory.MemoryMB * 1024 * 1024))
driverConfig.Properties["MemoryMax"] = strconv.Itoa(int(cfg.Resources.NomadResources.Memory.MemoryMaxMB * 1024 * 1024))
} else {
driverConfig.Properties["MemoryMax"] = strconv.Itoa(int(cfg.Resources.NomadResources.Memory.MemoryMB * 1024 * 1024))
}
}

// Setup port mapping and exposed ports
Expand All @@ -383,10 +388,10 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
}

if len(driverConfig.Ports) > 0 {
for _ , port := range driverConfig.Ports {
for _, port := range driverConfig.Ports {
p, ok := cfg.Resources.Ports.Get(port)
if !ok {
d.logger.Error("Port "+port+" not found, check network stanza")
d.logger.Error("Port " + port + " not found, check network stanza")
return nil, nil, fmt.Errorf("Port %q not found, check network stanza", port)
}
to := p.To
Expand Down

0 comments on commit 314f872

Please sign in to comment.