Merge pull request #6809 from jterry75/main

Add ctr support for CPUMax and CPUShares
This commit is contained in:
Phil Estes
2022-04-29 16:39:52 +01:00
committed by GitHub
4 changed files with 54 additions and 13 deletions

View File

@@ -83,6 +83,10 @@ func setResources(s *Spec) {
s.Linux.Resources = &specs.LinuxResources{}
}
}
}
// nolint
func setResourcesWindows(s *Spec) {
if s.Windows != nil {
if s.Windows.Resources == nil {
s.Windows.Resources = &specs.WindowsResources{}
@@ -98,6 +102,11 @@ func setCPU(s *Spec) {
s.Linux.Resources.CPU = &specs.LinuxCPU{}
}
}
}
// nolint
func setCPUWindows(s *Spec) {
setResourcesWindows(s)
if s.Windows != nil {
if s.Windows.Resources.CPU == nil {
s.Windows.Resources.CPU = &specs.WindowsCPUResources{}

View File

@@ -31,17 +31,32 @@ import (
// `count` specified.
func WithWindowsCPUCount(count uint64) SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
if s.Windows.Resources == nil {
s.Windows.Resources = &specs.WindowsResources{}
}
if s.Windows.Resources.CPU == nil {
s.Windows.Resources.CPU = &specs.WindowsCPUResources{}
}
setCPUWindows(s)
s.Windows.Resources.CPU.Count = &count
return nil
}
}
// WithWindowsCPUShares sets the `Windows.Resources.CPU.Shares` section to the
// `shares` specified.
func WithWindowsCPUShares(shares uint16) SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
setCPUWindows(s)
s.Windows.Resources.CPU.Shares = &shares
return nil
}
}
// WithWindowsCPUMaximum sets the `Windows.Resources.CPU.Maximum` section to the
// `max` specified.
func WithWindowsCPUMaximum(max uint16) SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
setCPUWindows(s)
s.Windows.Resources.CPU.Maximum = &max
return nil
}
}
// WithWindowsIgnoreFlushesDuringBoot sets `Windows.IgnoreFlushesDuringBoot`.
func WithWindowsIgnoreFlushesDuringBoot() SpecOpts {
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {