Skip to content
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

Generate correct output on NumCPU() when using cgroups2 #9816

Merged
merged 34 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e4a1129
file parsing for Cgroup2
nickorlow Mar 30, 2023
221e85f
added version detecting
nickorlow Mar 31, 2023
3ae35a0
ran gofmt
nickorlow Mar 31, 2023
7f64726
declarations to assignments
nickorlow Mar 31, 2023
a080ea1
correct types
nickorlow Mar 31, 2023
f35dae9
added test boilerplate
nickorlow Apr 16, 2023
dad8086
added test boilerplate
nickorlow Apr 16, 2023
7c4ac85
more boilerplate
nickorlow Apr 16, 2023
165d057
added a thing
sridharnandigam Apr 16, 2023
405a5aa
add some e2e tests (unfinished) + fix findMountPoint bug
nickorlow Apr 24, 2023
aa9a876
typo
nickorlow Apr 24, 2023
3714c2c
move error check
nickorlow Apr 25, 2023
6d96e11
try to figure out testing flags
nickorlow Apr 26, 2023
475adf7
add files
nickorlow Apr 26, 2023
c5dad5e
removed e2e tests for cgroups2 and associated functions
nickorlow May 12, 2023
a8028a5
remove test report
nickorlow May 12, 2023
ad1fb03
remove linux tag
nickorlow May 12, 2023
fddf4e0
fix formatting
nickorlow Jun 1, 2023
a9f9793
update default value for period when not set
nickorlow Jul 16, 2023
8f86603
Merge branch 'main' of github.com:nickorlow/ingress-nginx
nickorlow Jul 16, 2023
3814e1f
write e2e tests for cgroups
nickorlow Jul 16, 2023
8621dfc
fix e2e tests for cgroups
nickorlow Jul 16, 2023
0f4d054
gofmt
nickorlow Jul 17, 2023
c23cc0c
Merge branch 'kubernetes:main' into main
nickorlow Jul 17, 2023
b270b4a
remove build flags and rename cgroups_linux.go
nickorlow Jul 17, 2023
3a64d74
Merge branch 'main' of github.com:nickorlow/ingress-nginx
nickorlow Jul 17, 2023
30dc629
remove junit
nickorlow Jul 17, 2023
be6f1d5
gofmt
nickorlow Jul 17, 2023
0a01f55
bump to rerun ci
nickorlow Feb 21, 2024
63fb4c6
bump to rerun ci
nickorlow Feb 21, 2024
9e79a36
Merge branch 'kubernetes:main' into main
nickorlow May 18, 2024
ac0f6fc
fix lint errors
nickorlow May 18, 2024
b2d67ff
fix tests
nickorlow May 20, 2024
e9f3717
fix v1 test
nickorlow May 20, 2024
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
Prev Previous commit
Next Next commit
fix lint errors
nickorlow committed May 18, 2024
commit ac0f6fcd398065bd2ce54c655480a7ed32526127
11 changes: 4 additions & 7 deletions pkg/util/runtime/cpu_linux.go
Original file line number Diff line number Diff line change
@@ -64,14 +64,13 @@ func GetCgroupVersion() int64 {
// /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1
if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil {
return 2
} else {
return 1
}
}

func readCgroup2FileToInt64Tuple(cgroupFile string) (int64, int64) {
contents, err := os.ReadFile(filepath.Join("/sys/fs/cgroup/", cgroupFile))
return 1
}

func readCgroup2FileToInt64Tuple(cgroupFile string) (quota, period int64) {
contents, err := os.ReadFile(filepath.Join(string(os.PathSeparator), "sys", "fs", "cgroup", cgroupFile))
if err != nil {
return -1, -1
}
@@ -87,7 +86,6 @@ func readCgroup2FileToInt64Tuple(cgroupFile string) (int64, int64) {
}

cpuQuota, err := strconv.ParseInt(values[0], 10, 64)

if err != nil {
return -1, -1
}
@@ -97,7 +95,6 @@ func readCgroup2FileToInt64Tuple(cgroupFile string) (int64, int64) {
}

cpuPeriod, err := strconv.ParseInt(values[1], 10, 64)

if err != nil {
return -1, -1
}
40 changes: 31 additions & 9 deletions test/e2e/cgroups/cgroups.go
Original file line number Diff line number Diff line change
@@ -19,14 +19,14 @@ package cgroups
import (
"log"
"os"
"path/filepath"

"github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/assert"

"k8s.io/ingress-nginx/test/e2e/framework"

"k8s.io/ingress-nginx/pkg/util/runtime"
"path/filepath"

libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
)
@@ -46,22 +46,34 @@ var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
}

quotaFile, err := os.Create(filepath.Join(cgroupPath, "cpu.cfs_quota_us"))

if err != nil {
log.Fatal(err)
}

periodFile, err := os.Create(filepath.Join(cgroupPath, "cpu.cfs_period_us"))
if err != nil {
log.Fatal(err)
}

_, err = quotaFile.WriteString("4")
if err != nil {
log.Fatal(err)
}

quotaFile.WriteString("4")
quotaFile.Sync()
err = quotaFile.Sync()
if err != nil {
log.Fatal(err)
}

_, err = periodFile.WriteString("2")
if err != nil {
log.Fatal(err)
}

periodFile.WriteString("2")
periodFile.Sync()
err = periodFile.Sync()
if err != nil {
log.Fatal(err)
}

assert.Equal(ginkgo.GinkgoT(), runtime.GetCgroupVersion(), int64(1))
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), 2)
@@ -75,15 +87,25 @@ var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
log.Fatal(err)
}

os.Create("/sys/fs/cgroup/cgroup.controllers")
_, err := os.Create("/sys/fs/cgroup/cgroup.controllers")
if err != nil {
log.Fatal(err)
}

file, err := os.Create("/sys/fs/cgroup/cpu.max")
if err != nil {
log.Fatal(err)
}

_, err = file.WriteString("4 2")
if err != nil {
log.Fatal(err)
}

file.WriteString("4 2")
file.Sync()
err = file.Sync()
if err != nil {
log.Fatal(err)
}

assert.Equal(ginkgo.GinkgoT(), runtime.GetCgroupVersion(), int64(2))
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), 2)