tests: k8s-cpu-ns: Adapt to cgroupsv2

The changes done are:
* cpu/cpu.shares was replaced by cpu.weight
  * The weight, according to our reference[0], is calculated by:
    weight = (1 + ((request - 2) * 9999) / 262142)

* cpu/cpu.cfs_quota_us & cpu/cpu.cfs_period_us were replaced by cpu.max,
  where quota and period are written together (in this order)

[0]: https://github.com/containers/crun/blob/main/crun.1.md#cgroup-v2

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
This commit is contained in:
Fabiano Fidêncio 2025-01-10 15:58:19 +01:00
parent 4307f0c998
commit 0626d7182a

View File

@ -21,11 +21,15 @@ setup() {
pod_name="constraints-cpu-test"
container_name="first-cpu-container"
sharessyspath="/sys/fs/cgroup/cpu/cpu.shares"
quotasyspath="/sys/fs/cgroup/cpu/cpu.cfs_quota_us"
periodsyspath="/sys/fs/cgroup/cpu/cpu.cfs_period_us"
weightsyspath="/sys/fs/cgroup/cpu.weight"
maxsyspath="/sys/fs/cgroup/cpu.max"
total_cpus=2
total_requests=512
# https://github.com/containers/crun/blob/main/crun.1.md#cgroup-v2
# The weight is calculated by the:
# weight = (1 + ((request - 2) * 9999) / 262142)
total_requests=20
total_cpu_container=1
get_pod_config_dir
@ -38,17 +42,13 @@ setup() {
exec_num_cpus_cmd=(sh -c "${num_cpus_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_num_cpus_cmd[@]}"
quotasyspath_cmd="cat ${quotasyspath}"
exec_quotasyspath_cmd=(sh -c "${quotasyspath_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_quotasyspath_cmd[@]}"
maxsyspath_cmd="cat ${maxsyspath}"
exec_maxsyspath_cmd=(sh -c "${maxsyspath_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_maxsyspath_cmd[@]}"
periodsyspath_cmd="cat ${periodsyspath}"
exec_periodsyspath_cmd=(sh -c "${periodsyspath_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_periodsyspath_cmd[@]}"
sharessyspath_cmd="cat ${sharessyspath}"
exec_sharessyspath_cmd=(sh -c "${sharessyspath_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_sharessyspath_cmd[@]}"
weightsyspath_cmd="cat ${weightsyspath}"
exec_weightsyspath_cmd=(sh -c "${weightsyspath_cmd}")
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_weightsyspath_cmd[@]}"
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
auto_generate_policy "${policy_settings_dir}" "${yaml_file}"
@ -77,18 +77,15 @@ setup() {
# Check the total of requests
total_requests_container=$(kubectl exec $pod_name -c $container_name \
-- "${exec_sharessyspath_cmd[@]}")
-- "${exec_weightsyspath_cmd[@]}")
info "total_requests_container = $total_requests_container"
[ "$total_requests_container" -eq "$total_requests" ]
# Check the cpus inside the container
total_cpu_quota=$(kubectl exec $pod_name -c $container_name \
-- "${exec_quotasyspath_cmd[@]}")
total_cpu_period=$(kubectl exec $pod_name -c $container_name \
-- "${exec_periodsyspath_cmd[@]}")
read total_cpu_quota total_cpu_period <<< $(kubectl exec $pod_name -c $container_name \
-- "${exec_maxsyspath_cmd[@]}")
division_quota_period=$(echo $((total_cpu_quota/total_cpu_period)))