Add --cpu-quota, --cpu-period flag to ctr

Signed-off-by: Kenneth Kang <kenneth.kang@lge.com>
This commit is contained in:
kenneth.kang 2020-07-30 19:35:19 +09:00
parent 85b15eff45
commit e20a5079e8
2 changed files with 16 additions and 0 deletions

View File

@ -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",
})
}

View File

@ -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, ":")