Skip to content

Commit d2f3b71

Browse files
committed
add cpu-shares to ctr
This allows the cpu shares to be modified via ctr. Signed-off-by: Michael Crosby <[email protected]>
1 parent c7e4747 commit d2f3b71

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

cmd/ctr/commands/run/run_unix.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ var platformRunFlags = []cli.Flag{
7070
Usage: "set the CFS cpu quota",
7171
Value: 0.0,
7272
},
73+
cli.IntFlag{
74+
Name: "cpu-shares",
75+
Usage: "set the cpu shares",
76+
Value: 1024,
77+
},
7378
cli.BoolFlag{
7479
Name: "cni",
7580
Usage: "enable cni networking for the container",
@@ -226,6 +231,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
226231
opts = append(opts, oci.WithCPUCFS(quota, period))
227232
}
228233

234+
if shares := context.Int("cpu-shares"); shares > 0 {
235+
opts = append(opts, oci.WithCPUShares(uint64(shares)))
236+
}
237+
229238
quota := context.Int64("cpu-quota")
230239
period := context.Uint64("cpu-period")
231240
if quota != -1 || period != 0 {

oci/spec_opts_nonlinux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ var WithAllCurrentCapabilities = func(ctx context.Context, client Client, c *con
3636
var WithAllKnownCapabilities = func(ctx context.Context, client Client, c *containers.Container, s *Spec) error {
3737
return WithCapabilities(nil)(ctx, client, c, s)
3838
}
39+
40+
// WithCPUShares sets the container's cpu shares
41+
//nolint: deadcode, unused
42+
func WithCPUShares(shares uint64) SpecOpts {
43+
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {
44+
return nil
45+
}
46+
}

0 commit comments

Comments
 (0)