mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #70678 from dashpole/fix_cgroup_manager
Fix slice sharing bug in cgroup manager
This commit is contained in:
commit
f1bf9bef5c
@ -67,7 +67,10 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName {
|
|||||||
panic(fmt.Errorf("invalid character in component [%q] of CgroupName", component))
|
panic(fmt.Errorf("invalid character in component [%q] of CgroupName", component))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CgroupName(append(base, components...))
|
// copy data from the base cgroup to eliminate cases where CgroupNames share underlying slices. See #68416
|
||||||
|
baseCopy := make([]string, len(base))
|
||||||
|
copy(baseCopy, base)
|
||||||
|
return CgroupName(append(baseCopy, components...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func escapeSystemdCgroupName(part string) string {
|
func escapeSystemdCgroupName(part string) string {
|
||||||
|
@ -20,9 +20,34 @@ package cm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestNewCgroupName tests confirms that #68416 is fixed
|
||||||
|
func TestNewCgroupName(t *testing.T) {
|
||||||
|
a := ParseCgroupfsToCgroupName("/a/")
|
||||||
|
ab := NewCgroupName(a, "b")
|
||||||
|
|
||||||
|
expectedAB := CgroupName([]string{"a", "", "b"})
|
||||||
|
if !reflect.DeepEqual(ab, expectedAB) {
|
||||||
|
t.Errorf("Expected %d%+v; got %d%+v", len(expectedAB), expectedAB, len(ab), ab)
|
||||||
|
}
|
||||||
|
|
||||||
|
abc := NewCgroupName(ab, "c")
|
||||||
|
|
||||||
|
expectedABC := CgroupName([]string{"a", "", "b", "c"})
|
||||||
|
if !reflect.DeepEqual(abc, expectedABC) {
|
||||||
|
t.Errorf("Expected %d%+v; got %d%+v", len(expectedABC), expectedABC, len(abc), abc)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = NewCgroupName(ab, "d")
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(abc, expectedABC) {
|
||||||
|
t.Errorf("Expected %d%+v; got %d%+v", len(expectedABC), expectedABC, len(abc), abc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCgroupNameToSystemdBasename(t *testing.T) {
|
func TestCgroupNameToSystemdBasename(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
input CgroupName
|
input CgroupName
|
||||||
|
Loading…
Reference in New Issue
Block a user