Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
}
memoryLimit = resources.MemorySwapLimitInBytes
}
specgen.SetLinuxResourcesMemorySwap(memoryLimit)
// If node doesn't have memory swap, then skip setting
// otherwise the container creation fails.
if node.CgroupHasMemorySwap() {
specgen.SetLinuxResourcesMemorySwap(memoryLimit)
}
}

specgen.SetProcessOOMScoreAdj(int(resources.OomScoreAdj))
Expand Down
17 changes: 17 additions & 0 deletions test/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ function teardown() {
! crictl run "$newconfig" "$TESTDATA"/sandbox_config.json
}

@test "ctr swap only configured if enabled" {
set_swap_fields_given_cgroup_version
if test -r "$CGROUP_MEM_SWAP_FILE"; then
skip "swap cgroup enabled"
fi
start_crio
# memsw should be greater than or equal to memory limit
# 210763776 = 1024*1024*200
jq ' .linux.resources.memory_swap_limit_in_bytes = 210763776
| .linux.resources.memory_limit_in_bytes = 209715200' \
"$TESTDATA"/container_sleep.json > "$newconfig"

ctr_id=$(crictl run "$newconfig" "$TESTDATA"/sandbox_config.json)
# verify CRI-O did not specify memory swap value
jq -e .linux.resources.memory.swap "$(runtime list | grep "$ctr_id" | awk '{ print $4 }')/config.json"
}

@test "cgroupv2 unified support" {
if ! is_cgroup_v2; then
skip "node must be configured with cgroupv2 for this test"
Expand Down