write e2e tests for cgroups
This commit is contained in:
parent
475adf734a
commit
3814e1f01f
4 changed files with 92 additions and 1325 deletions
|
@ -38,7 +38,7 @@ import (
|
||||||
func NumCPU() int {
|
func NumCPU() int {
|
||||||
cpus := runtime.NumCPU()
|
cpus := runtime.NumCPU()
|
||||||
|
|
||||||
cgroupVersion := getCgroupVersion()
|
cgroupVersion := GetCgroupVersion()
|
||||||
cpuQuota := int64(-1)
|
cpuQuota := int64(-1)
|
||||||
cpuPeriod := int64(-1)
|
cpuPeriod := int64(-1)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func IsCgroupAvaliable() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCgroupVersion() int64 {
|
func GetCgroupVersion() int64 {
|
||||||
// /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1
|
// /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1
|
||||||
if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil {
|
if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil {
|
||||||
return 2
|
return 2
|
||||||
|
|
|
@ -28,7 +28,10 @@ import (
|
||||||
|
|
||||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
|
|
||||||
|
"path/filepath"
|
||||||
"k8s.io/ingress-nginx/pkg/util/runtime"
|
"k8s.io/ingress-nginx/pkg/util/runtime"
|
||||||
|
|
||||||
|
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
|
var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
|
||||||
|
@ -40,26 +43,75 @@ var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("detects if cgroups is avaliable", func() {
|
ginkgo.It("detects if cgroups is avaliable", func() {
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.IsCgroupAvaliable(), 1)
|
assert.True(ginkgo.GinkgoT(), runtime.IsCgroupAvaliable())
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("detects cgroups version v1", func() {
|
ginkgo.It("detects cgroups version v1", func() {
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.readCgroupFileToInt64(), 1)
|
cgroupPath, err := libcontainercgroups.FindCgroupMountpoint("", "cpu")
|
||||||
})
|
if err != nil {
|
||||||
|
|
||||||
ginkgo.It("detects number of CPUs properly in cgroups v1", func() {
|
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
|
||||||
})
|
|
||||||
|
|
||||||
ginkgo.It("detects cgroups version v2", func() {
|
|
||||||
// create cgroups2 files
|
|
||||||
if err := os.MkdirAll("a/b/c/d", os.ModePerm); err != nil {
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
quotaFile.WriteString("4");
|
||||||
|
quotaFile.Sync();
|
||||||
|
|
||||||
|
periodFile.WriteString("2");
|
||||||
|
periodFile.Sync();
|
||||||
|
|
||||||
|
assert.Equal(ginkgo.GinkgoT(), runtime.GetCgroupVersion(), int64(1))
|
||||||
|
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), 2)
|
||||||
|
|
||||||
|
os.Remove(filepath.Join(cgroupPath,"cpu.cfs_quota_us"))
|
||||||
|
os.Remove(filepath.Join(cgroupPath,"cpu.cfs_period_us"))
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("detects number of CPUs properly in cgroups v2", func() {
|
ginkgo.It("detect cgroups version v2", func() {
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
if err := os.MkdirAll("/sys/fs/cgroup/", os.ModePerm); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Create("/sys/fs/cgroup/cgroup.controllers")
|
||||||
|
file, err := os.Create("/sys/fs/cgroup/cpu.max")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file.WriteString("4 2");
|
||||||
|
file.Sync();
|
||||||
|
|
||||||
|
assert.Equal(ginkgo.GinkgoT(), runtime.GetCgroupVersion(), int64(2))
|
||||||
|
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), 2)
|
||||||
|
|
||||||
|
os.Remove("/sys/fs/cgroup/cpu.max")
|
||||||
|
os.Remove("/sys/fs/cgroup/cgroup.controllers")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// ginkgo.It("detects number of CPUs properly in cgroups v1", func() {
|
||||||
|
// assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
||||||
|
// })
|
||||||
|
|
||||||
|
// ginkgo.It("detects cgroups version v2", func() {
|
||||||
|
// // create cgroups2 files
|
||||||
|
// if err := os.MkdirAll("a/b/c/d", os.ModePerm); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// })
|
||||||
|
|
||||||
|
// ginkgo.It("detects number of CPUs properly in cgroups v2", func() {
|
||||||
|
// assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
||||||
|
// })
|
||||||
})
|
})
|
||||||
|
|
|
@ -29,27 +29,26 @@ import (
|
||||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
|
|
||||||
// tests to run
|
// tests to run
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/admission"
|
_ "k8s.io/ingress-nginx/test/e2e/admission"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/annotations"
|
_ "k8s.io/ingress-nginx/test/e2e/annotations"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/annotations/modsecurity"
|
_ "k8s.io/ingress-nginx/test/e2e/annotations/modsecurity"
|
||||||
_ "k8s.io/ingress-nginx/test/e2e/cgroups"
|
_ "k8s.io/ingress-nginx/test/e2e/dbg"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/dbg"
|
_ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/defaultbackend"
|
_ "k8s.io/ingress-nginx/test/e2e/endpointslices"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/endpointslices"
|
_ "k8s.io/ingress-nginx/test/e2e/gracefulshutdown"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/gracefulshutdown"
|
_ "k8s.io/ingress-nginx/test/e2e/ingress"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/ingress"
|
_ "k8s.io/ingress-nginx/test/e2e/leaks"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/leaks"
|
_ "k8s.io/ingress-nginx/test/e2e/loadbalance"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/loadbalance"
|
_ "k8s.io/ingress-nginx/test/e2e/lua"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/lua"
|
_ "k8s.io/ingress-nginx/test/e2e/nginx"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/nginx"
|
_ "k8s.io/ingress-nginx/test/e2e/security"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/security"
|
_ "k8s.io/ingress-nginx/test/e2e/servicebackend"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/servicebackend"
|
_ "k8s.io/ingress-nginx/test/e2e/settings"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/settings"
|
_ "k8s.io/ingress-nginx/test/e2e/settings/modsecurity"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/settings/modsecurity"
|
_ "k8s.io/ingress-nginx/test/e2e/settings/ocsp"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/settings/ocsp"
|
_ "k8s.io/ingress-nginx/test/e2e/ssl"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/ssl"
|
_ "k8s.io/ingress-nginx/test/e2e/status"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/status"
|
_ "k8s.io/ingress-nginx/test/e2e/tcpudp"
|
||||||
// _ "k8s.io/ingress-nginx/test/e2e/tcpudp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunE2ETests checks configuration parameters (specified through flags) and then runs
|
// RunE2ETests checks configuration parameters (specified through flags) and then runs
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue