Fix reserved cgroup systemd

Fix an issue in which, when trying to specify the `--kube-reserved-cgroup`
(or `--system-reserved-cgroup`) with `--cgroup-driver=systemd`, we will
not properly convert the `systemd` cgroup name into the internal cgroup
name that k8s expects. Without this change, specifying
`--kube-reserved-cgroup=/test.slice --cgroup-driver=systemd` will fail,
and only `--kube-reserved-cgroup=/test --crgroup-driver=systemd` will succeed,
even if the actual cgroup existing on the host is `/test.slice`.

Additionally, add light unit testing of our process from converting to a
systemd cgroup name to kubernetes internal cgroup name.
This commit is contained in:
mattjmcnaughton
2019-06-07 10:48:42 -04:00
parent 46a80259f6
commit 5539e61032
2 changed files with 24 additions and 2 deletions

View File

@@ -146,3 +146,25 @@ func TestCgroupNameToCgroupfs(t *testing.T) {
}
}
}
func TestParseSystemdToCgroupName(t *testing.T) {
testCases := []struct {
input string
expected CgroupName
}{
{
input: "/test",
expected: []string{"test"},
},
{
input: "/test.slice",
expected: []string{"test"},
},
}
for _, testCase := range testCases {
if actual := ParseSystemdToCgroupName(testCase.input); !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v", testCase.input, testCase.expected, actual)
}
}
}