Skip to content

Commit 6870ad3

Browse files
committed
test/ctr.bats: fix wrt new CPU units to weight conversion
It's a long story (see [1], [2], [3], [4]) but both runc and crun is changing the formula to convert cgroup v1 CPU shares to cgroup v2 CPU weight, and it causes a failure in "ctr update resources" test, because it relies on the old conversion formula. Let's modify it so it works either the old or the new conversion. (Ultimately, with cgroup v2 we should switch to setting unified.cpu.weight directly). [1]: kubernetes/kubernetes#131216 [2]: opencontainers/runc#4772 [3]: opencontainers/cgroups#20 [4]: containers/crun#1767 Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 19e0c14 commit 6870ad3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/ctr.bats

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,10 @@ function assert_log_linking() {
869869
[[ "$output" == *"20000 10000"* ]]
870870

871871
output=$(crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpu.weight")
872-
# 512 shares are converted to cpu.weight 20
873-
[[ "$output" == *"20"* ]]
872+
# CPU shares of 512 is converted to cpu.weight of either 20 or 59,
873+
# depending on crun/runc version (see https://github.com/kubernetes/kubernetes/issues/131216).
874+
echo "got cpu.weight $output, want 20 or 59"
875+
[ "$output" = "20" ] || [ "$output" = "59" ]
874876
else
875877
output=$(crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpu/cpu.shares")
876878
[[ "$output" == *"512"* ]]
@@ -897,8 +899,10 @@ function assert_log_linking() {
897899
[[ "$output" == *"10000 20000"* ]]
898900

899901
output=$(crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpu.weight")
900-
# 256 shares are converted to cpu.weight 10
901-
[[ "$output" == *"10"* ]]
902+
# CPU shares of 256 is converted to cpu.weight of either 10 or 35,
903+
# depending on crun/runc version (see https://github.com/kubernetes/kubernetes/issues/131216).
904+
echo "got cpu.weight $output, want 10 or 35"
905+
[ "$output" = "10" ] || [ "$output" = "35" ]
902906
else
903907
output=$(crictl exec --sync "$ctr_id" sh -c "cat /sys/fs/cgroup/cpu/cpu.shares")
904908
[[ "$output" == *"256"* ]]

0 commit comments

Comments
 (0)