Merge pull request #1236 from runcom/cpuset-ctr-create
container_create: set cpuset cpus|mems
This commit is contained in:
commit
6b91df3da7
3 changed files with 38 additions and 23 deletions
|
@ -785,28 +785,13 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
|||
if linux != nil {
|
||||
resources := linux.GetResources()
|
||||
if resources != nil {
|
||||
cpuPeriod := resources.CpuPeriod
|
||||
if cpuPeriod != 0 {
|
||||
specgen.SetLinuxResourcesCPUPeriod(uint64(cpuPeriod))
|
||||
}
|
||||
|
||||
cpuQuota := resources.CpuQuota
|
||||
if cpuQuota != 0 {
|
||||
specgen.SetLinuxResourcesCPUQuota(cpuQuota)
|
||||
}
|
||||
|
||||
cpuShares := resources.CpuShares
|
||||
if cpuShares != 0 {
|
||||
specgen.SetLinuxResourcesCPUShares(uint64(cpuShares))
|
||||
}
|
||||
|
||||
memoryLimit := resources.MemoryLimitInBytes
|
||||
if memoryLimit != 0 {
|
||||
specgen.SetLinuxResourcesMemoryLimit(memoryLimit)
|
||||
}
|
||||
|
||||
oomScoreAdj := resources.OomScoreAdj
|
||||
specgen.SetProcessOOMScoreAdj(int(oomScoreAdj))
|
||||
specgen.SetLinuxResourcesCPUPeriod(uint64(resources.GetCpuPeriod()))
|
||||
specgen.SetLinuxResourcesCPUQuota(resources.GetCpuQuota())
|
||||
specgen.SetLinuxResourcesCPUShares(uint64(resources.GetCpuShares()))
|
||||
specgen.SetLinuxResourcesMemoryLimit(resources.GetMemoryLimitInBytes())
|
||||
specgen.SetProcessOOMScoreAdj(int(resources.GetOomScoreAdj()))
|
||||
specgen.SetLinuxResourcesCPUCpus(resources.GetCpusetCpus())
|
||||
specgen.SetLinuxResourcesCPUMems(resources.GetCpusetMems())
|
||||
}
|
||||
|
||||
var cgPath string
|
||||
|
|
|
@ -1061,3 +1061,31 @@ function teardown() {
|
|||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
||||
@test "ctr resources" {
|
||||
start_crio
|
||||
run crictl runs "$TESTDATA"/sandbox_config.json
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
pod_id="$output"
|
||||
run crictl create "$pod_id" "$TESTDATA"/container_redis.json "$TESTDATA"/sandbox_config.json
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
ctr_id="$output"
|
||||
run crictl start "$ctr_id"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpuset/cpuset.cpus"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0-1" ]]
|
||||
run crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpuset/cpuset.mems"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0" ]]
|
||||
|
||||
cleanup_ctrs
|
||||
cleanup_pods
|
||||
stop_crio
|
||||
}
|
||||
|
|
4
test/testdata/container_redis.json
vendored
4
test/testdata/container_redis.json
vendored
|
@ -49,7 +49,9 @@
|
|||
"cpu_period": 10000,
|
||||
"cpu_quota": 20000,
|
||||
"cpu_shares": 512,
|
||||
"oom_score_adj": 30
|
||||
"oom_score_adj": 30,
|
||||
"cpuset_cpus": "0-1",
|
||||
"cpuset_mems": "0"
|
||||
},
|
||||
"security_context": {
|
||||
"capabilities": {
|
||||
|
|
Loading…
Reference in a new issue