Apply memory cgroups to the container.

This commit is contained in:
Shishir Mahajan 2020-09-25 16:41:30 -07:00
parent 737e022a1b
commit d49a03d6c6
No known key found for this signature in database
GPG Key ID: D41782E7688DEC4A
2 changed files with 5 additions and 2 deletions

View File

@ -41,7 +41,7 @@ func (d *Driver) pullImage(imageName string) (containerd.Image, error) {
return d.client.Pull(d.ctxContainerd, imageName, containerd.WithPullUnpack)
}
func (d *Driver) createContainer(image containerd.Image, containerName, containerSnapshotName, containerdRuntime, netnsPath, secretsDir, taskDir, allocDir string, env []string, config *TaskConfig) (containerd.Container, error) {
func (d *Driver) createContainer(image containerd.Image, containerName, containerSnapshotName, containerdRuntime, netnsPath, secretsDir, taskDir, allocDir string, env []string, memoryLimit int64, config *TaskConfig) (containerd.Container, error) {
if config.Command == "" && len(config.Args) > 0 {
return nil, fmt.Errorf("Command is empty. Cannot set --args without --command.")
}
@ -105,6 +105,9 @@ func (d *Driver) createContainer(image containerd.Image, containerName, containe
// Set environment variables.
opts = append(opts, oci.WithEnv(env))
// Set cgroups memory limit.
opts = append(opts, oci.WithMemoryLimit(uint64(memoryLimit)))
// Add linux devices into the container.
for _, device := range config.Devices {
opts = append(opts, oci.WithLinuxDevice(device, "rwm"))

View File

@ -380,7 +380,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
netnsPath = cfg.NetworkIsolation.Path
}
container, err := d.createContainer(image, containerName, containerSnapshotName, d.config.ContainerdRuntime, netnsPath, secretsDir, taskDir, allocDir, env, &driverConfig)
container, err := d.createContainer(image, containerName, containerSnapshotName, d.config.ContainerdRuntime, netnsPath, secretsDir, taskDir, allocDir, env, cfg.Resources.LinuxResources.MemoryLimitBytes, &driverConfig)
if err != nil {
return nil, nil, fmt.Errorf("Error in creating container: %v", err)
}