Use a []string for CgroupName, which is a more accurate internal representation
The slice of strings more precisely captures the hierarchic nature of the cgroup paths we use to represent pods and their groupings. It also ensures we're reducing the chances of passing an incorrect path format to a cgroup driver that requires a different path naming, since now explicit conversions are always needed. The new constructor NewCgroupName starts from an existing CgroupName, which enforces a hierarchy where a root is always needed. It also performs checking on the component names to ensure invalid characters ("/" and "_") are not in use. A RootCgroupName for the top of the cgroup hierarchy tree is introduced. This refactor results in a net reduction of around 30 lines of code, mainly with the demise of ConvertCgroupNameToSystemd which had fairly complicated logic in it and was doing just too many things. There's a small TODO in a helper updateSystemdCgroupInfo that was introduced to make this commit possible. That logic really belongs in libcontainer, I'm planning to send a PR there to include it there. (The API already takes a field with that information, only that field is only processed in cgroupfs and not systemd driver, we should fix that.) Tested by running the e2e-node tests on both Ubuntu 16.04 (with cgroupfs driver) and CentOS 7 (with systemd driver.)
This commit is contained in:
@@ -18,7 +18,6 @@ package cm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -60,17 +59,17 @@ type qosContainerManagerImpl struct {
|
||||
qosReserved map[v1.ResourceName]int64
|
||||
}
|
||||
|
||||
func NewQOSContainerManager(subsystems *CgroupSubsystems, cgroupRoot string, nodeConfig NodeConfig, cgroupManager CgroupManager) (QOSContainerManager, error) {
|
||||
func NewQOSContainerManager(subsystems *CgroupSubsystems, cgroupRoot CgroupName, nodeConfig NodeConfig, cgroupManager CgroupManager) (QOSContainerManager, error) {
|
||||
if !nodeConfig.CgroupsPerQOS {
|
||||
return &qosContainerManagerNoop{
|
||||
cgroupRoot: CgroupName(cgroupRoot),
|
||||
cgroupRoot: cgroupRoot,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &qosContainerManagerImpl{
|
||||
subsystems: subsystems,
|
||||
cgroupManager: cgroupManager,
|
||||
cgroupRoot: CgroupName(cgroupRoot),
|
||||
cgroupRoot: cgroupRoot,
|
||||
qosReserved: nodeConfig.QOSReserved,
|
||||
}, nil
|
||||
}
|
||||
@@ -81,23 +80,20 @@ func (m *qosContainerManagerImpl) GetQOSContainersInfo() QOSContainersInfo {
|
||||
|
||||
func (m *qosContainerManagerImpl) Start(getNodeAllocatable func() v1.ResourceList, activePods ActivePodsFunc) error {
|
||||
cm := m.cgroupManager
|
||||
rootContainer := string(m.cgroupRoot)
|
||||
if !cm.Exists(CgroupName(rootContainer)) {
|
||||
return fmt.Errorf("root container %s doesn't exist", rootContainer)
|
||||
rootContainer := m.cgroupRoot
|
||||
if !cm.Exists(rootContainer) {
|
||||
return fmt.Errorf("root container %v doesn't exist", rootContainer)
|
||||
}
|
||||
|
||||
// Top level for Qos containers are created only for Burstable
|
||||
// and Best Effort classes
|
||||
qosClasses := map[v1.PodQOSClass]string{
|
||||
v1.PodQOSBurstable: path.Join(rootContainer, strings.ToLower(string(v1.PodQOSBurstable))),
|
||||
v1.PodQOSBestEffort: path.Join(rootContainer, strings.ToLower(string(v1.PodQOSBestEffort))),
|
||||
qosClasses := map[v1.PodQOSClass]CgroupName{
|
||||
v1.PodQOSBurstable: NewCgroupName(rootContainer, strings.ToLower(string(v1.PodQOSBurstable))),
|
||||
v1.PodQOSBestEffort: NewCgroupName(rootContainer, strings.ToLower(string(v1.PodQOSBestEffort))),
|
||||
}
|
||||
|
||||
// Create containers for both qos classes
|
||||
for qosClass, containerName := range qosClasses {
|
||||
// get the container's absolute name
|
||||
absoluteContainerName := CgroupName(containerName)
|
||||
|
||||
resourceParameters := &ResourceConfig{}
|
||||
// the BestEffort QoS class has a statically configured minShares value
|
||||
if qosClass == v1.PodQOSBestEffort {
|
||||
@@ -107,7 +103,7 @@ func (m *qosContainerManagerImpl) Start(getNodeAllocatable func() v1.ResourceLis
|
||||
|
||||
// containerConfig object stores the cgroup specifications
|
||||
containerConfig := &CgroupConfig{
|
||||
Name: absoluteContainerName,
|
||||
Name: containerName,
|
||||
ResourceParameters: resourceParameters,
|
||||
}
|
||||
|
||||
@@ -117,7 +113,7 @@ func (m *qosContainerManagerImpl) Start(getNodeAllocatable func() v1.ResourceLis
|
||||
}
|
||||
|
||||
// check if it exists
|
||||
if !cm.Exists(absoluteContainerName) {
|
||||
if !cm.Exists(containerName) {
|
||||
if err := cm.Create(containerConfig); err != nil {
|
||||
return fmt.Errorf("failed to create top level %v QOS cgroup : %v", qosClass, err)
|
||||
}
|
||||
@@ -279,11 +275,11 @@ func (m *qosContainerManagerImpl) UpdateCgroups() error {
|
||||
|
||||
qosConfigs := map[v1.PodQOSClass]*CgroupConfig{
|
||||
v1.PodQOSBurstable: {
|
||||
Name: CgroupName(m.qosContainersInfo.Burstable),
|
||||
Name: m.qosContainersInfo.Burstable,
|
||||
ResourceParameters: &ResourceConfig{},
|
||||
},
|
||||
v1.PodQOSBestEffort: {
|
||||
Name: CgroupName(m.qosContainersInfo.BestEffort),
|
||||
Name: m.qosContainersInfo.BestEffort,
|
||||
ResourceParameters: &ResourceConfig{},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user