hashicorp / nomad-driver-podman

A nomad task driver plugin for sandboxing workloads in podman containers
https://developer.hashicorp.com/nomad/plugins/drivers/podman
Mozilla Public License 2.0
224 stars 61 forks source link

driver: set cpuset when using cgroups v2 #252

Closed shoenig closed 1 year ago

shoenig commented 1 year ago

This PR makes it so that the Podman driver will now respect the task config resources.cores value. When set, the task will be assigned the specified number of CPU cores to be allowed to run on.

Note: unlike the docker/exec drivers, podman tasks will not be also allowed to make use of the "shared" set of cpu cores (ones that have not yet been reserved specifically for a task). Most likely that feature will be removed in the near future (~Nomad 1.7) anyway.

Closes #160

shoenig commented 1 year ago

Spot check, just run a job with some cores using tasks and inspect their cgroup cpuset interface files.

basic job ```hcl job "sleep" { group "group" { count = 4 task "sleep" { driver = "podman" config { image = "docker.io/bash:5" args = ["sleep", "infinity"] } resources { cores = 2 memory = 64 } } } } ```

inspecting cpusets, each is assigned 2 cores

➜ cat /sys/fs/cgroup/nomad.slice/libpod*/container/cpuset.cpus.effective
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /sys/fs/cgroup/nomad.slice/libpod-71531bfec2f731bd685dda3257c1ee258739abffff2f8133ad99518d86eb43bc.scope/container/cpuset.cpus.effective
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 14-15
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /sys/fs/cgroup/nomad.slice/libpod-9f884865bd52af3ef6474f0ca7d5ff9ae3798d58f48b795735ab2a302a61875b.scope/container/cpuset.cpus.effective
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 16-17
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /sys/fs/cgroup/nomad.slice/libpod-b1057260dbdff72fd119c1f5b98e783af2deef12a10f03426884b8c15143820c.scope/container/cpuset.cpus.effective
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 10-11
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /sys/fs/cgroup/nomad.slice/libpod-bc3f041ef6d8cc75e2a2c1de60006d36285d5f415c0815acdc2496f239358c6e.scope/container/cpuset.cpus.effective
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ 12-13
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────