Skip to content

Commit 7284a8e

Browse files
shishir-a412edolljanat
authored andcommitted
Add support for cpuset_cpus and cpuset_mems
Signed-off-by: Shishir Mahajan <[email protected]>
1 parent cc0da22 commit 7284a8e

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ To interact with `images` and `containers` directly, you can use [`nerdctl`](htt
123123
| **extra_hosts** | []string | no | A list of hosts, given as host:IP, to be added to /etc/hosts. |
124124
| **cap_add** | []string | no | Add individual capabilities. |
125125
| **cap_drop** | []string | no | Drop invidual capabilities. |
126+
| **cpuset_cpus** | string | no | CPUs in which to allow execution (0-3, 0,1). |
127+
| **cpuset_mems** | string | no | MEMs in which to allow execution (0-3, 0,1). |
126128
| **devices** | []string | no | A list of devices to be exposed to the container. |
127129
| **auth** | block | no | Provide authentication for a private registry. See [Authentication](#authentication-private-registry) for more details. |
128130
| **mounts** | []block | no | A list of mounts to be mounted in the container. Volume, bind and tmpfs type mounts are supported. fstab style [`mount options`](https://github.com/containerd/containerd/blob/master/mount/mount_linux.go#L211-L235) are supported. |

Vagrantfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VAGRANTFILE_API_VERSION = "2"
55
# Create box
66
Vagrant.configure("2") do |config|
77
config.vm.define "containerd-linux"
8-
config.vm.box = "hashicorp/bionic64"
8+
config.vm.box = "generic/ubuntu2204"
99
config.vm.provider "libvirt" do |v, override|
1010
override.vm.box = "generic/debian10"
1111
override.vm.synced_folder ".", "/home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd", type: "nfs", nfs_version: 4, nfs_udp: false
@@ -20,7 +20,7 @@ Vagrant.configure("2") do |config|
2020
end
2121
config.vm.provision "shell", inline: <<-SHELL
2222
apt-get update
23-
apt-get install -y unzip gcc runc jq
23+
apt-get install -y unzip gcc runc jq make
2424
echo "export GOPATH=/home/vagrant/go" >> /home/vagrant/.bashrc
2525
echo "export PATH=$PATH:/usr/local/go/bin" >> /home/vagrant/.bashrc
2626
echo "export CONTAINERD_NAMESPACE=nomad" >> /home/vagrant/.bashrc

containerd/containerd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
217217
opts = append(opts, oci.WithDroppedCapabilities(config.CapDrop))
218218
}
219219

220+
// This translates to docker create/run --cpuset-cpus option.
221+
// --cpuset-cpus limit the specific CPUs or cores a container can use.
222+
if config.CPUSetCPUs != "" {
223+
opts = append(opts, oci.WithCPUs(config.CPUSetCPUs))
224+
}
225+
226+
// --cpuset-mems is the list of memory nodes on which processes
227+
// in this cpuset are allowed to allocate memory.
228+
if config.CPUSetMEMs != "" {
229+
opts = append(opts, oci.WithCPUsMems(config.CPUSetMEMs))
230+
}
231+
220232
// Set current working directory (cwd).
221233
if config.Cwd != "" {
222234
opts = append(opts, oci.WithProcessCwd(config.Cwd))

containerd/driver.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,19 @@ var (
9696
// this is used to validate the configuration specified for the plugin
9797
// when a job is submitted.
9898
taskConfigSpec = hclspec.NewObject(map[string]*hclspec.Spec{
99-
"image": hclspec.NewAttr("image", "string", true),
100-
"command": hclspec.NewAttr("command", "string", false),
101-
"args": hclspec.NewAttr("args", "list(string)", false),
102-
"cap_add": hclspec.NewAttr("cap_add", "list(string)", false),
103-
"cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false),
104-
"cwd": hclspec.NewAttr("cwd", "string", false),
105-
"devices": hclspec.NewAttr("devices", "list(string)", false),
106-
"privileged": hclspec.NewAttr("privileged", "bool", false),
107-
"pids_limit": hclspec.NewAttr("pids_limit", "number", false),
108-
"pid_mode": hclspec.NewAttr("pid_mode", "string", false),
109-
"hostname": hclspec.NewAttr("hostname", "string", false),
99+
"image": hclspec.NewAttr("image", "string", true),
100+
"command": hclspec.NewAttr("command", "string", false),
101+
"args": hclspec.NewAttr("args", "list(string)", false),
102+
"cap_add": hclspec.NewAttr("cap_add", "list(string)", false),
103+
"cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false),
104+
"cpuset_cpus": hclspec.NewAttr("cpuset_cpus", "string", false),
105+
"cpuset_mems": hclspec.NewAttr("cpuset_mems", "string", false),
106+
"cwd": hclspec.NewAttr("cwd", "string", false),
107+
"devices": hclspec.NewAttr("devices", "list(string)", false),
108+
"privileged": hclspec.NewAttr("privileged", "bool", false),
109+
"pids_limit": hclspec.NewAttr("pids_limit", "number", false),
110+
"pid_mode": hclspec.NewAttr("pid_mode", "string", false),
111+
"hostname": hclspec.NewAttr("hostname", "string", false),
110112
"host_dns": hclspec.NewDefault(
111113
hclspec.NewAttr("host_dns", "bool", false),
112114
hclspec.NewLiteral("true"),
@@ -181,6 +183,8 @@ type TaskConfig struct {
181183
Args []string `codec:"args"`
182184
CapAdd []string `codec:"cap_add"`
183185
CapDrop []string `codec:"cap_drop"`
186+
CPUSetCPUs string `codec:"cpuset_cpus"`
187+
CPUSetMEMs string `codec:"cpuset_mems"`
184188
Cwd string `codec:"cwd"`
185189
Devices []string `codec:"devices"`
186190
Seccomp bool `codec:"seccomp"`

example/redis.nomad

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ job "redis" {
66
driver = "containerd-driver"
77

88
config {
9-
image = "redis:alpine"
10-
hostname = "foobar"
11-
seccomp = true
12-
cwd = "/home/redis"
9+
image = "redis:alpine"
10+
hostname = "foobar"
11+
seccomp = true
12+
cwd = "/home/redis"
13+
cpuset_cpus = "0-1"
14+
cpuset_mems = "0"
1315
}
1416

1517
resources {

0 commit comments

Comments
 (0)