Skip to content

Commit 84acb25

Browse files
committed
Move constants to the top
1 parent f5e2ac0 commit 84acb25

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

client/driver/rkt.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ var (
2929
reAppcVersion = regexp.MustCompile(`appc version (\d[.\d]+)`)
3030
)
3131

32+
const (
33+
// rkt added support for CPU and memory isolators in 0.14.0. We cannot support
34+
// an earlier version to maintain an uniform interface across all drivers
35+
minRktVersion = "0.14.0"
36+
conversionFactor = 1024 * 1024
37+
)
38+
3239
// RktDriver is a driver for running images via Rkt
3340
// We attempt to chose sane defaults for now, with more configuration available
3441
// planned in the future
@@ -86,7 +93,7 @@ func (d *RktDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, e
8693
node.Attributes["driver.rkt.version"] = rktMatches[1]
8794
node.Attributes["driver.rkt.appc.version"] = appcMatches[1]
8895

89-
minVersion, _ := version.NewVersion("0.14.0")
96+
minVersion, _ := version.NewVersion(minRktVersion)
9097
currentVersion, _ := version.NewVersion(node.Attributes["driver.rkt.version"])
9198
if currentVersion.LessThan(minVersion) {
9299
// Do not allow rkt < 0.14.0
@@ -165,7 +172,7 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e
165172
}
166173

167174
// Add memory isolator
168-
cmdArgs = append(cmdArgs, fmt.Sprintf("--memory=%vM", int64(task.Resources.MemoryMB)*1024*1024))
175+
cmdArgs = append(cmdArgs, fmt.Sprintf("--memory=%vM", int64(task.Resources.MemoryMB)*conversionFactor))
169176

170177
// Add CPU isolator
171178
cmdArgs = append(cmdArgs, fmt.Sprintf("--cpu=%vm", int64(task.Resources.CPU)))

0 commit comments

Comments
 (0)