Skip to content

Commit 3702731

Browse files
committed
Set default CPU limit as 2 and show in TMDEv2/v3/v4 task metadata
1 parent 6962e07 commit 3702731

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

agent/handlers/v2/response.go

+10
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ type ErrorResponse struct {
9494
ResourceARN string `json:"ResourceARN,omitempty"`
9595
}
9696

97+
// Agent versions >= 1.2.0: Null, zero, and CPU values of 1
98+
// are passed to Docker as two CPU shares
99+
const minimumCPUUnit = 2
100+
97101
// NewTaskResponse creates a new response object for the task
98102
func NewTaskResponse(
99103
taskARN string,
@@ -234,6 +238,12 @@ func NewContainerResponse(
234238
ExitCode: container.GetKnownExitCode(),
235239
Labels: container.GetLabels(),
236240
}
241+
242+
if container.CPU < minimumCPUUnit {
243+
defaultCPU := func(val float64) *float64 { return &val }(minimumCPUUnit)
244+
resp.Limits.CPU = defaultCPU
245+
}
246+
237247
// V4 metadata endpoint calls this function for consistency across versions,
238248
// but needs additional metadata only available at this scope.
239249
if includeV4Metadata {

agent/handlers/v2/response_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func TestTaskResponseMarshal(t *testing.T) {
351351
"DesiredStatus": "NONE",
352352
"KnownStatus": "NONE",
353353
"Limits": map[string]interface{}{
354-
"CPU": float64(0),
354+
"CPU": float64(2),
355355
"Memory": float64(0),
356356
},
357357
"Type": "NORMAL",

0 commit comments

Comments
 (0)