Merge pull request #9205 from lengrongfu/feat/add-cpu-burst

This commit is contained in:
Samuel Karp 2023-10-12 23:55:00 -07:00 committed by GitHub
commit 8ed0255f1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {