ctr: add cpuset-cpus flag to 'ctr run' command

This flag allows cpuset.cpus to be specified when starting a container. If
provided, the container will use only the defined CPU cores.

Signed-off-by: Peteris Rudzusiks <rye@stripe.com>
This commit is contained in:
Peteris Rudzusiks 2023-05-30 16:20:58 +02:00
parent 4b7145cfd3
commit f642c0a5f5

View File

@ -82,6 +82,10 @@ var platformRunFlags = []cli.Flag{
Usage: "Set the cpu shares", Usage: "Set the cpu shares",
Value: 1024, Value: 1024,
}, },
cli.StringFlag{
Name: "cpuset-cpus",
Usage: "Set the CPUs the container will run in (e.g., 1-2,4)",
},
} }
// NewContainer creates a new container // NewContainer creates a new container
@ -293,6 +297,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
opts = append(opts, oci.WithCPUCFS(quota, period)) opts = append(opts, oci.WithCPUCFS(quota, period))
} }
if cpusetCpus := context.String("cpuset-cpus"); len(cpusetCpus) > 0 {
opts = append(opts, oci.WithCPUs(cpusetCpus))
}
if shares := context.Int("cpu-shares"); shares > 0 { if shares := context.Int("cpu-shares"); shares > 0 {
opts = append(opts, oci.WithCPUShares(uint64(shares))) opts = append(opts, oci.WithCPUShares(uint64(shares)))
} }