Merge pull request #5846 from crosbymichael/ctr-cpu.shares

This commit is contained in:
Fu Wei 2021-08-11 09:24:00 +08:00 committed by GitHub
commit 1c4e9d0487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -72,6 +72,11 @@ var platformRunFlags = []cli.Flag{
Usage: "set the CFS cpu quota", Usage: "set the CFS cpu quota",
Value: 0.0, Value: 0.0,
}, },
cli.IntFlag{
Name: "cpu-shares",
Usage: "set the cpu shares",
Value: 1024,
},
cli.BoolFlag{ cli.BoolFlag{
Name: "cni", Name: "cni",
Usage: "enable cni networking for the container", Usage: "enable cni networking for the container",
@ -231,6 +236,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 shares := context.Int("cpu-shares"); shares > 0 {
opts = append(opts, oci.WithCPUShares(uint64(shares)))
}
quota := context.Int64("cpu-quota") quota := context.Int64("cpu-quota")
period := context.Uint64("cpu-period") period := context.Uint64("cpu-period")
if quota != -1 || period != 0 { if quota != -1 || period != 0 {

View File

@ -36,3 +36,11 @@ var WithAllCurrentCapabilities = func(ctx context.Context, client Client, c *con
var WithAllKnownCapabilities = func(ctx context.Context, client Client, c *containers.Container, s *Spec) error { var WithAllKnownCapabilities = func(ctx context.Context, client Client, c *containers.Container, s *Spec) error {
return WithCapabilities(nil)(ctx, client, c, s) return WithCapabilities(nil)(ctx, client, c, s)
} }
// WithCPUShares sets the container's cpu shares
//nolint: deadcode, unused
func WithCPUShares(shares uint64) SpecOpts {
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {
return nil
}
}