Commit 10dd03c0 authored by Darren Shepherd's avatar Darren Shepherd Committed by Erik Wilson

Delete systemd cgroup support

parent feb98fa7
...@@ -27,7 +27,6 @@ import ( ...@@ -27,7 +27,6 @@ import (
units "github.com/docker/go-units" units "github.com/docker/go-units"
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups" libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs" cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs"
cgroupsystemd "github.com/opencontainers/runc/libcontainer/cgroups/systemd"
libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs" libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs"
rsystem "github.com/opencontainers/runc/libcontainer/system" rsystem "github.com/opencontainers/runc/libcontainer/system"
"k8s.io/klog" "k8s.io/klog"
...@@ -44,10 +43,6 @@ type libcontainerCgroupManagerType string ...@@ -44,10 +43,6 @@ type libcontainerCgroupManagerType string
const ( const (
// libcontainerCgroupfs means use libcontainer with cgroupfs // libcontainerCgroupfs means use libcontainer with cgroupfs
libcontainerCgroupfs libcontainerCgroupManagerType = "cgroupfs" libcontainerCgroupfs libcontainerCgroupManagerType = "cgroupfs"
// libcontainerSystemd means use libcontainer with systemd
libcontainerSystemd libcontainerCgroupManagerType = "systemd"
// systemdSuffix is the cgroup name suffix for systemd
systemdSuffix string = ".slice"
) )
// hugePageSizeList is useful for converting to the hugetlb canonical unit // hugePageSizeList is useful for converting to the hugetlb canonical unit
...@@ -74,48 +69,6 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName { ...@@ -74,48 +69,6 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName {
return CgroupName(append(baseCopy, components...)) return CgroupName(append(baseCopy, components...))
} }
func escapeSystemdCgroupName(part string) string {
return strings.Replace(part, "-", "_", -1)
}
func unescapeSystemdCgroupName(part string) string {
return strings.Replace(part, "_", "-", -1)
}
// cgroupName.ToSystemd converts the internal cgroup name to a systemd name.
// For example, the name {"kubepods", "burstable", "pod1234-abcd-5678-efgh"} becomes
// "/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod1234_abcd_5678_efgh.slice"
// This function always expands the systemd name into the cgroupfs form. If only
// the last part is needed, use path.Base(...) on it to discard the rest.
func (cgroupName CgroupName) ToSystemd() string {
if len(cgroupName) == 0 || (len(cgroupName) == 1 && cgroupName[0] == "") {
return "/"
}
newparts := []string{}
for _, part := range cgroupName {
part = escapeSystemdCgroupName(part)
newparts = append(newparts, part)
}
result, err := cgroupsystemd.ExpandSlice(strings.Join(newparts, "-") + systemdSuffix)
if err != nil {
// Should never happen...
panic(fmt.Errorf("error converting cgroup name [%v] to systemd format: %v", cgroupName, err))
}
return result
}
func ParseSystemdToCgroupName(name string) CgroupName {
driverName := path.Base(name)
driverName = strings.TrimSuffix(driverName, systemdSuffix)
parts := strings.Split(driverName, "-")
result := []string{}
for _, part := range parts {
result = append(result, unescapeSystemdCgroupName(part))
}
return CgroupName(result)
}
func (cgroupName CgroupName) ToCgroupfs() string { func (cgroupName CgroupName) ToCgroupfs() string {
return "/" + path.Join(cgroupName...) return "/" + path.Join(cgroupName...)
} }
...@@ -128,10 +81,6 @@ func ParseCgroupfsToCgroupName(name string) CgroupName { ...@@ -128,10 +81,6 @@ func ParseCgroupfsToCgroupName(name string) CgroupName {
return CgroupName(components) return CgroupName(components)
} }
func IsSystemdStyleName(name string) bool {
return strings.HasSuffix(name, systemdSuffix)
}
// libcontainerAdapter provides a simplified interface to libcontainer based on libcontainer type. // libcontainerAdapter provides a simplified interface to libcontainer based on libcontainer type.
type libcontainerAdapter struct { type libcontainerAdapter struct {
// cgroupManagerType defines how to interface with libcontainer // cgroupManagerType defines how to interface with libcontainer
...@@ -153,15 +102,6 @@ func (l *libcontainerAdapter) newManager(cgroups *libcontainerconfigs.Cgroup, pa ...@@ -153,15 +102,6 @@ func (l *libcontainerAdapter) newManager(cgroups *libcontainerconfigs.Cgroup, pa
Rootless: rsystem.RunningInUserNS(), Rootless: rsystem.RunningInUserNS(),
Paths: paths, Paths: paths,
}, nil }, nil
case libcontainerSystemd:
// this means you asked systemd to manage cgroups, but systemd was not on the host, so all you can do is panic...
if !cgroupsystemd.UseSystemd() {
panic("systemd cgroup manager not available")
}
return &cgroupsystemd.Manager{
Cgroups: cgroups,
Paths: paths,
}, nil
} }
return nil, fmt.Errorf("invalid cgroup manager configuration") return nil, fmt.Errorf("invalid cgroup manager configuration")
} }
...@@ -195,9 +135,6 @@ var _ CgroupManager = &cgroupManagerImpl{} ...@@ -195,9 +135,6 @@ var _ CgroupManager = &cgroupManagerImpl{}
// NewCgroupManager is a factory method that returns a CgroupManager // NewCgroupManager is a factory method that returns a CgroupManager
func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager { func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager {
managerType := libcontainerCgroupfs managerType := libcontainerCgroupfs
if cgroupDriver == string(libcontainerSystemd) {
managerType = libcontainerSystemd
}
return &cgroupManagerImpl{ return &cgroupManagerImpl{
subsystems: cs, subsystems: cs,
adapter: newLibcontainerAdapter(managerType), adapter: newLibcontainerAdapter(managerType),
...@@ -207,17 +144,11 @@ func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager { ...@@ -207,17 +144,11 @@ func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager {
// Name converts the cgroup to the driver specific value in cgroupfs form. // Name converts the cgroup to the driver specific value in cgroupfs form.
// This always returns a valid cgroupfs path even when systemd driver is in use! // This always returns a valid cgroupfs path even when systemd driver is in use!
func (m *cgroupManagerImpl) Name(name CgroupName) string { func (m *cgroupManagerImpl) Name(name CgroupName) string {
if m.adapter.cgroupManagerType == libcontainerSystemd {
return name.ToSystemd()
}
return name.ToCgroupfs() return name.ToCgroupfs()
} }
// CgroupName converts the literal cgroupfs name on the host to an internal identifier. // CgroupName converts the literal cgroupfs name on the host to an internal identifier.
func (m *cgroupManagerImpl) CgroupName(name string) CgroupName { func (m *cgroupManagerImpl) CgroupName(name string) CgroupName {
if m.adapter.cgroupManagerType == libcontainerSystemd {
return ParseSystemdToCgroupName(name)
}
return ParseCgroupfsToCgroupName(name) return ParseCgroupfsToCgroupName(name)
} }
...@@ -231,22 +162,6 @@ func (m *cgroupManagerImpl) buildCgroupPaths(name CgroupName) map[string]string ...@@ -231,22 +162,6 @@ func (m *cgroupManagerImpl) buildCgroupPaths(name CgroupName) map[string]string
return cgroupPaths return cgroupPaths
} }
// TODO(filbranden): This logic belongs in libcontainer/cgroup/systemd instead.
// It should take a libcontainerconfigs.Cgroup.Path field (rather than Name and Parent)
// and split it appropriately, using essentially the logic below.
// This was done for cgroupfs in opencontainers/runc#497 but a counterpart
// for systemd was never introduced.
func updateSystemdCgroupInfo(cgroupConfig *libcontainerconfigs.Cgroup, cgroupName CgroupName) {
dir, base := path.Split(cgroupName.ToSystemd())
if dir == "/" {
dir = "-.slice"
} else {
dir = path.Base(dir)
}
cgroupConfig.Parent = dir
cgroupConfig.Name = base
}
// Exists checks if all subsystem cgroups already exist // Exists checks if all subsystem cgroups already exist
func (m *cgroupManagerImpl) Exists(name CgroupName) bool { func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
// Get map of all cgroup paths on the system for the particular cgroup // Get map of all cgroup paths on the system for the particular cgroup
...@@ -295,11 +210,7 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error { ...@@ -295,11 +210,7 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
libcontainerCgroupConfig := &libcontainerconfigs.Cgroup{} libcontainerCgroupConfig := &libcontainerconfigs.Cgroup{}
// libcontainer consumes a different field and expects a different syntax // libcontainer consumes a different field and expects a different syntax
// depending on the cgroup driver in use, so we need this conditional here. // depending on the cgroup driver in use, so we need this conditional here.
if m.adapter.cgroupManagerType == libcontainerSystemd { libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
} else {
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
}
manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths) manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths)
if err != nil { if err != nil {
...@@ -430,11 +341,7 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error { ...@@ -430,11 +341,7 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
} }
// libcontainer consumes a different field and expects a different syntax // libcontainer consumes a different field and expects a different syntax
// depending on the cgroup driver in use, so we need this conditional here. // depending on the cgroup driver in use, so we need this conditional here.
if m.adapter.cgroupManagerType == libcontainerSystemd { libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
} else {
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
}
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil { if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {
libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit
...@@ -461,11 +368,7 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error { ...@@ -461,11 +368,7 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
} }
// libcontainer consumes a different field and expects a different syntax // libcontainer consumes a different field and expects a different syntax
// depending on the cgroup driver in use, so we need this conditional here. // depending on the cgroup driver in use, so we need this conditional here.
if m.adapter.cgroupManagerType == libcontainerSystemd { libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name)
} else {
libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs()
}
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil { if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.SupportPodPidsLimit) && cgroupConfig.ResourceParameters != nil && cgroupConfig.ResourceParameters.PidsLimit != nil {
libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit libcontainerCgroupConfig.PidsLimit = *cgroupConfig.ResourceParameters.PidsLimit
......
...@@ -287,14 +287,8 @@ func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool { ...@@ -287,14 +287,8 @@ func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool {
// getCadvisorPodInfoFromPodUID returns a pod cgroup information by matching the podUID with its CgroupName identifier base name // getCadvisorPodInfoFromPodUID returns a pod cgroup information by matching the podUID with its CgroupName identifier base name
func getCadvisorPodInfoFromPodUID(podUID types.UID, infos map[string]cadvisorapiv2.ContainerInfo) *cadvisorapiv2.ContainerInfo { func getCadvisorPodInfoFromPodUID(podUID types.UID, infos map[string]cadvisorapiv2.ContainerInfo) *cadvisorapiv2.ContainerInfo {
for key, info := range infos { for key, info := range infos {
if cm.IsSystemdStyleName(key) { // Take last component only.
// Convert to internal cgroup name and take the last component only. key = path.Base(key)
internalCgroupName := cm.ParseSystemdToCgroupName(key)
key = internalCgroupName[len(internalCgroupName)-1]
} else {
// Take last component only.
key = path.Base(key)
}
if cm.GetPodCgroupNameSuffix(podUID) == key { if cm.GetPodCgroupNameSuffix(podUID) == key {
return &info return &info
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment