From cce8ef96af91ef016d07290cdfb65057c368c481 Mon Sep 17 00:00:00 2001 From: Chien-Han Lin Date: Tue, 5 Jan 2021 14:03:39 -0800 Subject: [PATCH] Set default CPU limit as 2 and show in TMDEv2/v3/v4 task metadata --- agent/handlers/v2/response.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agent/handlers/v2/response.go b/agent/handlers/v2/response.go index ea25cc28658..43b2d2833be 100644 --- a/agent/handlers/v2/response.go +++ b/agent/handlers/v2/response.go @@ -80,6 +80,10 @@ type LimitsResponse struct { Memory *int64 `json:"Memory,omitempty"` } +// Agent versions >= 1.2.0: Null, zero, and CPU values of 1 +// are passed to Docker as two CPU shares +const minimumCPUUnit = 2 + // NewTaskResponse creates a new response object for the task func NewTaskResponse( taskARN string, @@ -218,6 +222,12 @@ func NewContainerResponse( ExitCode: container.GetKnownExitCode(), Labels: container.GetLabels(), } + + if container.CPU < minimumCPUUnit { + defaultCPU := func(val float64) *float64 { return &val }(minimumCPUUnit) + resp.Limits.CPU = defaultCPU + } + // V4 metadata endpoint calls this function for consistency across versions, // but needs additional metadata only available at this scope. if includeV4Metadata {