diff --git a/pkg/kubelet/cm/cgroup_manager_linux.go b/pkg/kubelet/cm/cgroup_manager_linux.go index 0dbd71e08e..1e4149be66 100644 --- a/pkg/kubelet/cm/cgroup_manager_linux.go +++ b/pkg/kubelet/cm/cgroup_manager_linux.go @@ -27,7 +27,6 @@ import ( units "github.com/docker/go-units" libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups" cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs" - cgroupsystemd "github.com/opencontainers/runc/libcontainer/cgroups/systemd" libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs" "k8s.io/klog" @@ -43,10 +42,6 @@ type libcontainerCgroupManagerType string const ( // libcontainerCgroupfs means use libcontainer with 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 @@ -73,48 +68,6 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName { 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 { return "/" + path.Join(cgroupName...) } @@ -127,10 +80,6 @@ func ParseCgroupfsToCgroupName(name string) CgroupName { return CgroupName(components) } -func IsSystemdStyleName(name string) bool { - return strings.HasSuffix(name, systemdSuffix) -} - // libcontainerAdapter provides a simplified interface to libcontainer based on libcontainer type. type libcontainerAdapter struct { // cgroupManagerType defines how to interface with libcontainer @@ -151,15 +100,6 @@ func (l *libcontainerAdapter) newManager(cgroups *libcontainerconfigs.Cgroup, pa Cgroups: cgroups, Paths: paths, }, 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") } @@ -193,9 +133,6 @@ var _ CgroupManager = &cgroupManagerImpl{} // NewCgroupManager is a factory method that returns a CgroupManager func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager { managerType := libcontainerCgroupfs - if cgroupDriver == string(libcontainerSystemd) { - managerType = libcontainerSystemd - } return &cgroupManagerImpl{ subsystems: cs, adapter: newLibcontainerAdapter(managerType), @@ -205,17 +142,11 @@ func NewCgroupManager(cs *CgroupSubsystems, cgroupDriver string) CgroupManager { // 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! func (m *cgroupManagerImpl) Name(name CgroupName) string { - if m.adapter.cgroupManagerType == libcontainerSystemd { - return name.ToSystemd() - } return name.ToCgroupfs() } // CgroupName converts the literal cgroupfs name on the host to an internal identifier. func (m *cgroupManagerImpl) CgroupName(name string) CgroupName { - if m.adapter.cgroupManagerType == libcontainerSystemd { - return ParseSystemdToCgroupName(name) - } return ParseCgroupfsToCgroupName(name) } @@ -229,22 +160,6 @@ func (m *cgroupManagerImpl) buildCgroupPaths(name CgroupName) map[string]string 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 func (m *cgroupManagerImpl) Exists(name CgroupName) bool { // Get map of all cgroup paths on the system for the particular cgroup @@ -290,11 +205,7 @@ func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error { libcontainerCgroupConfig := &libcontainerconfigs.Cgroup{} // libcontainer consumes a different field and expects a different syntax // depending on the cgroup driver in use, so we need this conditional here. - if m.adapter.cgroupManagerType == libcontainerSystemd { - updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name) - } else { - libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() - } + libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() manager, err := m.adapter.newManager(libcontainerCgroupConfig, cgroupPaths) if err != nil { @@ -420,11 +331,7 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error { } // libcontainer consumes a different field and expects a different syntax // depending on the cgroup driver in use, so we need this conditional here. - if m.adapter.cgroupManagerType == libcontainerSystemd { - updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name) - } else { - libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() - } + libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() if err := setSupportedSubsystems(libcontainerCgroupConfig); err != nil { return fmt.Errorf("failed to set supported cgroup subsystems for cgroup %v: %v", cgroupConfig.Name, err) @@ -446,11 +353,7 @@ func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error { } // libcontainer consumes a different field and expects a different syntax // depending on the cgroup driver in use, so we need this conditional here. - if m.adapter.cgroupManagerType == libcontainerSystemd { - updateSystemdCgroupInfo(libcontainerCgroupConfig, cgroupConfig.Name) - } else { - libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() - } + libcontainerCgroupConfig.Path = cgroupConfig.Name.ToCgroupfs() // get the manager with the specified cgroup configuration manager, err := m.adapter.newManager(libcontainerCgroupConfig, nil) diff --git a/pkg/kubelet/stats/cadvisor_stats_provider.go b/pkg/kubelet/stats/cadvisor_stats_provider.go index 9549c12a1a..9c0e612bde 100644 --- a/pkg/kubelet/stats/cadvisor_stats_provider.go +++ b/pkg/kubelet/stats/cadvisor_stats_provider.go @@ -316,14 +316,8 @@ func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool { // 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 { for key, info := range infos { - if cm.IsSystemdStyleName(key) { - // Convert to internal cgroup name and take the last component only. - internalCgroupName := cm.ParseSystemdToCgroupName(key) - key = internalCgroupName[len(internalCgroupName)-1] - } else { - // Take last component only. - key = path.Base(key) - } + // Take last component only. + key = path.Base(key) if cm.GetPodCgroupNameSuffix(podUID) == key { return &info }