Skip to content

Commit 8716b82

Browse files
committed
chore: add cpushares option
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 63bfcff commit 8716b82

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

api/handlers/container/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
153153
PidsLimit: -1, // nerdctl default.
154154
Cgroupns: defaults.CgroupnsMode(), // nerdctl default.
155155
BlkioWeight: req.HostConfig.BlkioWeight, // block IO weight (relative)
156+
CPUPeriod: uint64(req.HostConfig.CPUPeriod),
156157
// #endregion
157158

158159
// #region for user flags

api/handlers/container/create_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,27 @@ var _ = Describe("Container Create API ", func() {
437437
Expect(rr.Body).Should(MatchJSON(jsonResponse))
438438
})
439439

440+
It("should set CPUPeriod create options for resources", func() {
441+
body := []byte(`{
442+
"Image": "test-image",
443+
"HostConfig": {
444+
"CpuPeriod": 100000
445+
}
446+
}`)
447+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
448+
449+
// expected create options
450+
createOpt.CPUPeriod = 100000
451+
452+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
453+
cid, nil)
454+
455+
// handler should return success message with 201 status code.
456+
h.create(rr, req)
457+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
458+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
459+
})
460+
440461
It("should return 404 if the image was not found", func() {
441462
body := []byte(`{"Image": "test-image"}`)
442463
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))

api/types/container_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type ContainerHostConfig struct {
102102
// Contains container's resources (cgroups, ulimits)
103103
CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
104104
Memory int64 // Memory limit (in bytes)
105+
CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period
105106
// TODO: Resources
106107

107108
BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)

0 commit comments

Comments
 (0)