add cpu-burst param to ctr command

Signed-off-by: rongfu.leng <rongfu.leng@daocloud.io>
This commit is contained in:
rongfu.leng 2023-10-09 21:51:24 +08:00
parent ecda3b88ce
commit 8f3d1c9d9b
2 changed files with 13 additions and 0 deletions

View File

@ -327,6 +327,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 burst := context.Uint64("cpu-burst"); burst != 0 {
opts = append(opts, oci.WithCPUBurst(burst))
}
joinNs := context.StringSlice("with-ns") joinNs := context.StringSlice("with-ns")
for _, ns := range joinNs { for _, ns := range joinNs {
nsType, nsPath, ok := strings.Cut(ns, ":") nsType, nsPath, ok := strings.Cut(ns, ":")

View File

@ -1535,6 +1535,15 @@ func WithCPUCFS(quota int64, period uint64) SpecOpts {
} }
} }
// WithCPUBurst sets the container's cpu burst
func WithCPUBurst(burst uint64) SpecOpts {
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {
setCPU(s)
s.Linux.Resources.CPU.Burst = &burst
return nil
}
}
// WithCPURT sets the container's realtime scheduling (RT) runtime and period. // WithCPURT sets the container's realtime scheduling (RT) runtime and period.
func WithCPURT(runtime int64, period uint64) SpecOpts { func WithCPURT(runtime int64, period uint64) SpecOpts {
return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error { return func(ctx context.Context, _ Client, c *containers.Container, s *Spec) error {