Skip to content

deps: bump opencontainers/cgroups to v0.0.2, fix tests #4751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/moby/sys/user v0.4.0
github.com/moby/sys/userns v0.1.0
github.com/mrunalp/fileutils v0.5.1
github.com/opencontainers/cgroups v0.0.1
github.com/opencontainers/cgroups v0.0.2
github.com/opencontainers/runtime-spec v1.2.1
github.com/opencontainers/selinux v1.12.0
github.com/seccomp/libseccomp-golang v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
github.com/mrunalp/fileutils v0.5.1 h1:F+S7ZlNKnrwHfSwdlgNSkKo67ReVf8o9fel6C3dkm/Q=
github.com/mrunalp/fileutils v0.5.1/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/opencontainers/cgroups v0.0.1 h1:MXjMkkFpKv6kpuirUa4USFBas573sSAY082B4CiHEVA=
github.com/opencontainers/cgroups v0.0.1/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs=
github.com/opencontainers/cgroups v0.0.2 h1:A+mAPPMfgKNCEZUUtibESFx06uvhAmvo8sSz3Abwk7o=
github.com/opencontainers/cgroups v0.0.2/go.mod h1:s8lktyhlGUqM7OSRL5P7eAW6Wb+kWPNvt4qvVfzA5vs=
github.com/opencontainers/runtime-spec v1.2.1 h1:S4k4ryNgEpxW1dzyqffOmhI1BHYcjzU8lpJfSlR0xww=
github.com/opencontainers/runtime-spec v1.2.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.12.0 h1:6n5JV4Cf+4y0KNXW48TLj5DwfXpvWlxXplUkdTrmPb8=
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cgroups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ convert_hugetlb_size() {
check_systemd_value "MemoryHigh" 5242880
check_systemd_value "MemoryMax" 10485760
check_systemd_value "TasksMax" 99
check_cpu_quota 10000 100000 "100ms"
check_cpu_quota 10000 100000
check_cpu_weight 42
}

Expand Down Expand Up @@ -390,7 +390,7 @@ convert_hugetlb_size() {
[ "$output" = '42' ]
check_systemd_value "TasksMax" 42

check_cpu_quota 5000 50000 "100ms"
check_cpu_quota 5000 50000

check_cpu_weight 42
}
Expand Down
30 changes: 27 additions & 3 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,33 @@ function check_systemd_value() {
function check_cpu_quota() {
local quota=$1
local period=$2
local sd_quota=$3
local sd_quota

if [ -v RUNC_USE_SYSTEMD ]; then
if [ "$quota" = "-1" ]; then
sd_quota="infinity"
else
# In systemd world, quota (CPUQuotaPerSec) is measured in ms
# (per second), and systemd rounds it up to 10ms. For example,
# given quota=4000 and period=10000, systemd value is 400ms.
#
# Calculate milliseconds (quota/period * 1000).
# First multiply by 1000 to get milliseconds,
# then add half of period for proper rounding.
local ms=$(((quota * 1000 + period / 2) / period))
# Round up to nearest 10ms.
ms=$(((ms + 5) / 10 * 10))
sd_quota="${ms}ms"

# Recalculate quota based on systemd value.
# Convert ms back to quota units.
quota=$((ms * period / 1000))

fi

# Systemd values are the same for v1 and v2.
check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota"
fi

if [ -v CGROUP_V2 ]; then
if [ "$quota" = "-1" ]; then
Expand All @@ -297,8 +323,6 @@ function check_cpu_quota() {
check_cgroup_value "cpu.cfs_quota_us" "$quota"
check_cgroup_value "cpu.cfs_period_us" "$period"
fi
# systemd values are the same for v1 and v2
check_systemd_value "CPUQuotaPerSecUSec" "$sd_quota"

# CPUQuotaPeriodUSec requires systemd >= v242
[ "$(systemd_version)" -lt 242 ] && return
Expand Down
56 changes: 28 additions & 28 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,26 @@ EOF
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

# check that initial values were properly set
check_cpu_quota 500000 1000000 "500ms"
# Check that initial values were properly set.
check_cpu_quota 500000 1000000
check_cpu_shares 100

# update cpu period
# Update cpu period.
runc update test_update --cpu-period 900000
[ "$status" -eq 0 ]
check_cpu_quota 500000 900000 "560ms"
check_cpu_quota 500000 900000

# update cpu quota
# Update cpu quota.
runc update test_update --cpu-quota 600000
[ "$status" -eq 0 ]
check_cpu_quota 600000 900000 "670ms"
check_cpu_quota 600000 900000

# remove cpu quota
# Remove cpu quota.
runc update test_update --cpu-quota -1
[ "$status" -eq 0 ]
check_cpu_quota -1 900000 "infinity"
check_cpu_quota -1 900000

# update cpu-shares
# Update cpu-shares.
runc update test_update --cpu-share 200
[ "$status" -eq 0 ]
check_cpu_shares 200
Expand All @@ -298,21 +298,21 @@ EOF
}
EOF
[ "$status" -eq 0 ]
check_cpu_quota 500000 1000000 "500ms"
check_cpu_quota 500000 1000000

# redo all the changes at once
# Redo all the changes at once.
runc update test_update \
--cpu-period 900000 --cpu-quota 600000 --cpu-share 200
[ "$status" -eq 0 ]
check_cpu_quota 600000 900000 "670ms"
check_cpu_quota 600000 900000
check_cpu_shares 200

# remove cpu quota and reset the period
# Remove cpu quota and reset the period.
runc update test_update --cpu-quota -1 --cpu-period 100000
[ "$status" -eq 0 ]
check_cpu_quota -1 100000 "infinity"
check_cpu_quota -1 100000

# reset to initial test value via json file
# Reset to initial test values via json file.
cat <<EOF >"$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json
{
"cpu": {
Expand All @@ -326,7 +326,7 @@ EOF

runc update -r "$BATS_RUN_TMPDIR"/runc-cgroups-integration-test.json test_update
[ "$status" -eq 0 ]
check_cpu_quota 500000 1000000 "500ms"
check_cpu_quota 500000 1000000
check_cpu_shares 100
}

Expand Down Expand Up @@ -363,7 +363,7 @@ EOF
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

check_cpu_quota -1 1000000 "infinity"
check_cpu_quota -1 1000000
}

@test "set cpu period with no quota (invalid period)" {
Expand All @@ -382,7 +382,7 @@ EOF

runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
check_cpu_quota 5000 100000 "50ms"
check_cpu_quota 5000 100000
}

@test "update cpu period with no previous period/quota set" {
Expand All @@ -393,10 +393,10 @@ EOF
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

# update the period alone, no old values were set
# Update the period alone, no old values were set.
runc update --cpu-period 50000 test_update
[ "$status" -eq 0 ]
check_cpu_quota -1 50000 "infinity"
check_cpu_quota -1 50000
}

@test "update cpu quota with no previous period/quota set" {
Expand All @@ -407,10 +407,10 @@ EOF
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

# update the quota alone, no old values were set
# Update the quota alone, no old values were set.
runc update --cpu-quota 30000 test_update
[ "$status" -eq 0 ]
check_cpu_quota 30000 100000 "300ms"
check_cpu_quota 30000 100000
}

@test "update cpu period in a pod cgroup with pod limit set" {
Expand Down Expand Up @@ -445,7 +445,7 @@ EOF
# Finally, the test itself: set 30% limit but with lower period.
runc update --cpu-period 10000 --cpu-quota 3000 test_update
[ "$status" -eq 0 ]
check_cpu_quota 3000 10000 "300ms"
check_cpu_quota 3000 10000
}

@test "update cgroup cpu.idle" {
Expand Down Expand Up @@ -545,9 +545,9 @@ EOF
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

# check that initial values were properly set
check_cpu_quota 500000 1000000 "500ms"
# initial cpu shares of 100 corresponds to weight of 4
# Check that initial values were properly set.
check_cpu_quota 500000 1000000
# Initial cpu shares of 100 corresponds to weight of 4.
check_cpu_weight 4
check_systemd_value "TasksMax" 20

Expand All @@ -561,8 +561,8 @@ EOF
}
EOF

# check the updated systemd unit properties
check_cpu_quota -1 100000 "infinity"
# Check the updated systemd unit properties.
check_cpu_quota -1 100000
check_cpu_weight 16
check_systemd_value "TasksMax" 10
}
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/opencontainers/cgroups/.golangci-extra.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/github.com/opencontainers/cgroups/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/opencontainers/cgroups/RELEASES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading