move error check
This commit is contained in:
parent
aa9a876217
commit
3714c2c426
2 changed files with 18 additions and 8 deletions
|
@ -38,16 +38,15 @@ import (
|
||||||
func NumCPU() int {
|
func NumCPU() int {
|
||||||
cpus := runtime.NumCPU()
|
cpus := runtime.NumCPU()
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return cpus
|
|
||||||
}
|
|
||||||
|
|
||||||
cgroupVersion := getCgroupVersion()
|
cgroupVersion := getCgroupVersion()
|
||||||
cpuQuota := int64(-1)
|
cpuQuota := int64(-1)
|
||||||
cpuPeriod := int64(-1)
|
cpuPeriod := int64(-1)
|
||||||
|
|
||||||
if cgroupVersion == 1 {
|
if cgroupVersion == 1 {
|
||||||
cgroupPath, err := libcontainercgroups.FindCgroupMountpoint("", "cpu")
|
cgroupPath, err := libcontainercgroups.FindCgroupMountpoint("", "cpu")
|
||||||
|
if err != nil {
|
||||||
|
return cpus
|
||||||
|
}
|
||||||
cpuQuota = readCgroupFileToInt64(cgroupPath, "cpu.cfs_quota_us")
|
cpuQuota = readCgroupFileToInt64(cgroupPath, "cpu.cfs_quota_us")
|
||||||
cpuPeriod = readCgroupFileToInt64(cgroupPath, "cpu.cfs_period_us")
|
cpuPeriod = readCgroupFileToInt64(cgroupPath, "cpu.cfs_period_us")
|
||||||
} else if cgroupVersion == 2 {
|
} else if cgroupVersion == 2 {
|
||||||
|
|
|
@ -17,6 +17,9 @@ limitations under the License.
|
||||||
package cgroups
|
package cgroups
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
@ -33,15 +36,23 @@ var _ = framework.IngressNginxDescribeSerial("[CGroups] cgroups", func() {
|
||||||
f.NewSlowEchoDeployment()
|
f.NewSlowEchoDeployment()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.It("detects cgroups version v1", func() {
|
||||||
|
assert.Equal(ginkgo.GinkgoT(), runtime.getCgroupVersion(), 1)
|
||||||
|
})
|
||||||
|
|
||||||
ginkgo.It("detects number of CPUs properly in cgroups v1", func() {
|
ginkgo.It("detects number of CPUs properly in cgroups v1", func() {
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
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() {
|
ginkgo.It("detects number of CPUs properly in cgroups v2", func() {
|
||||||
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
assert.Equal(ginkgo.GinkgoT(), runtime.NumCPU(), -1)
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("detects cgroups version", func() {
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue