Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/ctr/commands/commands_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
}
9 changes: 9 additions & 0 deletions cmd/ctr/commands/run/run_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ":")
Expand Down