fn: add storage opt size support (#860)

Added env FN_MAX_FS_SIZE_MB, which if defined and non-zero
is passed to docker as storage opt size. We do not validate
if this option is supported by docker currently. This is
because it's difficult to actually validate this since it
not only depends on storage driver and its backing filesystem,
but also the mount options used to mount that fs.
This commit is contained in:
Tolga Ceylan
2018-03-14 15:47:34 -07:00
committed by GitHub
parent b74db6762b
commit cb61a678d9
5 changed files with 24 additions and 5 deletions

View File

@@ -168,6 +168,13 @@ func (drv *DockerDriver) Prepare(ctx context.Context, task drivers.ContainerTask
container.HostConfig.CPUPeriod = 100000
}
// If defined, impose file system size limit. In MB units.
if task.FsSize() != 0 {
container.HostConfig.StorageOpt = make(map[string]string)
sizeOption := fmt.Sprintf("%vM", task.FsSize())
container.HostConfig.StorageOpt["size"] = sizeOption
}
volumes := task.Volumes()
for _, mapping := range volumes {
hostDir := mapping[0]

View File

@@ -33,6 +33,7 @@ func (f *taskDockerTest) WriteStat(context.Context, drivers.Stat) { /* TODO */ }
func (f *taskDockerTest) Volumes() [][2]string { return [][2]string{} }
func (f *taskDockerTest) Memory() uint64 { return 256 * 1024 * 1024 }
func (f *taskDockerTest) CPUs() uint64 { return 0 }
func (f *taskDockerTest) FsSize() uint64 { return 0 }
func (f *taskDockerTest) WorkDir() string { return "" }
func (f *taskDockerTest) Close() {}
func (f *taskDockerTest) Input() io.Reader { return f.input }