pkg/kubelet: adapt to new libcontainer API

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2020-04-23 09:11:27 +02:00
parent a6a3bf2eb4
commit e94aebf4cb
6 changed files with 164 additions and 115 deletions

View File

@@ -60,7 +60,11 @@ func fakeContainerMgrMountInt() mount.Interface {
func TestCgroupMountValidationSuccess(t *testing.T) {
f, err := validateSystemRequirements(fakeContainerMgrMountInt())
assert.Nil(t, err)
assert.False(t, f.cpuHardcapping, "cpu hardcapping is expected to be disabled")
if cgroups.IsCgroup2UnifiedMode() {
assert.True(t, f.cpuHardcapping, "cpu hardcapping is expected to be enabled")
} else {
assert.False(t, f.cpuHardcapping, "cpu hardcapping is expected to be disabled")
}
}
func TestCgroupMountValidationMemoryMissing(t *testing.T) {
@@ -115,6 +119,19 @@ func TestCgroupMountValidationMultipleSubsystem(t *testing.T) {
assert.Nil(t, err)
}
func TestGetCpuWeight(t *testing.T) {
assert.Equal(t, uint64(0), getCpuWeight(nil))
v := uint64(2)
assert.Equal(t, uint64(1), getCpuWeight(&v))
v = uint64(262144)
assert.Equal(t, uint64(10000), getCpuWeight(&v))
v = uint64(1000000000)
assert.Equal(t, uint64(10000), getCpuWeight(&v))
}
func TestSoftRequirementsValidationSuccess(t *testing.T) {
if cgroups.IsCgroup2UnifiedMode() {
t.Skip("skipping cgroup v1 test on a cgroup v2 system")
@@ -148,28 +165,3 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
assert.NoError(t, err)
assert.True(t, f.cpuHardcapping, "cpu hardcapping is expected to be enabled")
}
func TestGetCpuWeight(t *testing.T) {
assert.Equal(t, uint64(0), getCpuWeight(nil))
v := uint64(2)
assert.Equal(t, uint64(1), getCpuWeight(&v))
v = uint64(262144)
assert.Equal(t, uint64(10000), getCpuWeight(&v))
v = uint64(1000000000)
assert.Equal(t, uint64(10000), getCpuWeight(&v))
}
func TestGetCpuMax(t *testing.T) {
assert.Equal(t, getCpuMax(nil, nil), "max 100000")
quota := int64(50000)
period := uint64(200000)
assert.Equal(t, "50000 200000", getCpuMax(&quota, &period))
assert.Equal(t, "max 200000", getCpuMax(nil, &period))
assert.Equal(t, "50000 100000", getCpuMax(&quota, nil))
}