Apply memory cgroups to the container.
This commit is contained in:
parent
737e022a1b
commit
d49a03d6c6
@ -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"))
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user