From e20a5079e8c99b0a6eda609872d478a707043390 Mon Sep 17 00:00:00 2001 From: "kenneth.kang" Date: Thu, 30 Jul 2020 19:35:19 +0900 Subject: [PATCH] Add --cpu-quota, --cpu-period flag to ctr Signed-off-by: Kenneth Kang --- cmd/ctr/commands/commands_unix.go | 7 +++++++ cmd/ctr/commands/run/run_unix.go | 9 +++++++++ 2 files changed, 16 insertions(+) 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, ":")