From 6763b8d8663690f4500d444c935564bada5f0e35 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Thu, 29 Nov 2018 22:07:30 -0800 Subject: [PATCH] Adding CPU and Memory override OCI annotations Signed-off-by: Justin Terry (VM) --- cmd/runhcs/container.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/runhcs/container.go b/cmd/runhcs/container.go index 93e7dd2f9b..592017c64a 100644 --- a/cmd/runhcs/container.go +++ b/cmd/runhcs/container.go @@ -467,6 +467,8 @@ func createContainer(cfg *containerConfig) (_ *container, err error) { const ( annotationAllowOverCommit = "io.microsoft.virtualmachine.computetopology.memory.allowovercommit" annotationEnableDeferredCommit = "io.microsoft.virtualmachine.computetopology.memory.enabledeferredcommit" + annotationMemorySizeInMB = "io.microsoft.virtualmachine.computetopology.memory.sizeinmb" + annotationProcessorCount = "io.microsoft.virtualmachine.computetopology.processor.count" annotationVPMemCount = "io.microsoft.virtualmachine.devices.virtualpmem.maximumcount" annotationVPMemSize = "io.microsoft.virtualmachine.devices.virtualpmem.maximumsizebytes" annotationPreferredRootFSType = "io.microsoft.virtualmachine.lcow.preferredrootfstype" @@ -485,6 +487,26 @@ func createContainer(cfg *containerConfig) (_ *container, err error) { PreferredRootFSType: parseAnnotationsPreferredRootFSType(cfg.Spec.Annotations, annotationPreferredRootFSType), } + memSize := parseAnnotationsUint64(cfg.Spec.Annotations, annotationMemorySizeInMB) + cpuCount := parseAnnotationsUint64(cfg.Spec.Annotations, annotationProcessorCount) + if memSize != nil || cpuCount != nil { + if opts.Resources == nil { + opts.Resources = &specs.WindowsResources{} + } + if memSize != nil { + if opts.Resources.Memory == nil { + opts.Resources.Memory = &specs.WindowsMemoryResources{} + } + opts.Resources.Memory.Limit = memSize + } + if cpuCount != nil { + if opts.Resources.CPU == nil { + opts.Resources.CPU = &specs.WindowsCPUResources{} + } + opts.Resources.CPU.Count = cpuCount + } + } + shim, err := c.startVMShim(cfg.VMLogFile, opts) if err != nil { return nil, err