diff --git a/cmd/ctr/commands/commands_unix.go b/cmd/ctr/commands/commands_unix.go index a67fa8f6a..38ee594f0 100644 --- a/cmd/ctr/commands/commands_unix.go +++ b/cmd/ctr/commands/commands_unix.go @@ -29,5 +29,12 @@ func init() { }, cli.BoolFlag{ Name: "no-pivot", Usage: "disable use of pivot-root (linux only)", + }, cli.Int64Flag{ + Name: "cpu-quota", + Usage: "Limit CPU CFS quota", + Value: -1, + }, cli.Uint64Flag{ + Name: "cpu-period", + Usage: "Limit CPU CFS period", }) } diff --git a/cmd/ctr/commands/run/run_unix.go b/cmd/ctr/commands/run/run_unix.go index d84ed0238..45b8781ab 100644 --- a/cmd/ctr/commands/run/run_unix.go +++ b/cmd/ctr/commands/run/run_unix.go @@ -192,6 +192,15 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli opts = append(opts, oci.WithCPUCFS(quota, period)) } + quota := context.Int64("cpu-quota") + period := context.Uint64("cpu-period") + if quota != -1 || period != 0 { + if cpus := context.Float64("cpus"); cpus > 0.0 { + return nil, errors.New("cpus and quota/period should be used separately") + } + opts = append(opts, oci.WithCPUCFS(quota, period)) + } + joinNs := context.StringSlice("with-ns") for _, ns := range joinNs { parts := strings.Split(ns, ":")