From 8ab30afdc7bf28d9a525a5566d057504ee502ade Mon Sep 17 00:00:00 2001 From: Derek Carr Date: Fri, 24 Feb 2017 22:41:15 -0500 Subject: [PATCH] Fix get all pods from cgroups logic --- pkg/kubelet/cm/cgroup_manager_linux.go | 1 + pkg/kubelet/cm/pod_container_manager_linux.go | 41 +++++++++++-------- pkg/kubelet/kubelet_pods.go | 2 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/pkg/kubelet/cm/cgroup_manager_linux.go b/pkg/kubelet/cm/cgroup_manager_linux.go index 8e9ec04acde46..f7f44d5408c47 100644 --- a/pkg/kubelet/cm/cgroup_manager_linux.go +++ b/pkg/kubelet/cm/cgroup_manager_linux.go @@ -147,6 +147,7 @@ func (l *libcontainerAdapter) revertName(name string) CgroupName { panic(err) } driverName = strings.TrimSuffix(driverName, ".slice") + driverName = strings.Replace(driverName, "-", "/", -1) driverName = strings.Replace(driverName, "_", "-", -1) return CgroupName(driverName) } diff --git a/pkg/kubelet/cm/pod_container_manager_linux.go b/pkg/kubelet/cm/pod_container_manager_linux.go index 4468e4753a52a..06573a0aa89f0 100644 --- a/pkg/kubelet/cm/pod_container_manager_linux.go +++ b/pkg/kubelet/cm/pod_container_manager_linux.go @@ -200,24 +200,31 @@ func (m *podContainerManagerImpl) GetAllPodsFromCgroups() (map[types.UID]CgroupN return nil, fmt.Errorf("failed to read the cgroup directory %v : %v", qc, err) } for i := range dirInfo { - // note: we do a contains check because on systemd, the literal cgroupfs name will prefix the qos as well. - if dirInfo[i].IsDir() && strings.Contains(dirInfo[i].Name(), podCgroupNamePrefix) { - // we need to convert the name to an internal identifier - internalName := m.cgroupManager.CgroupName(dirInfo[i].Name()) - // we then split the name on the pod prefix to determine the uid - parts := strings.Split(string(internalName), podCgroupNamePrefix) - // the uid is missing, so we log the unexpected cgroup not of form pod - if len(parts) != 2 { - location := path.Join(qc, dirInfo[i].Name()) - glog.Errorf("pod cgroup manager ignoring unexpected cgroup %v because it is not a pod", location) - continue - } - podUID := parts[1] - // because the literal cgroupfs name could encode the qos tier (on systemd), we avoid double encoding - // by just rebuilding the fully qualified CgroupName according to our internal convention. - cgroupName := CgroupName(path.Join(qosContainerName, podCgroupNamePrefix+podUID)) - foundPods[types.UID(podUID)] = cgroupName + // its not a directory, so continue on... + if !dirInfo[i].IsDir() { + continue + } + // convert the concrete cgroupfs name back to an internal identifier + // this is needed to handle path conversion for systemd environments. + // we pass the fully qualified path so decoding can work as expected + // since systemd encodes the path in each segment. + cgroupfsPath := path.Join(qcConversion, dirInfo[i].Name()) + internalPath := m.cgroupManager.CgroupName(cgroupfsPath) + // we only care about base segment of the converted path since that + // is what we are reading currently to know if it is a pod or not. + basePath := path.Base(string(internalPath)) + if !strings.Contains(basePath, podCgroupNamePrefix) { + continue + } + // we then split the name on the pod prefix to determine the uid + parts := strings.Split(basePath, podCgroupNamePrefix) + // the uid is missing, so we log the unexpected cgroup not of form pod + if len(parts) != 2 { + glog.Errorf("pod cgroup manager ignoring unexpected cgroup %v because it is not a pod", cgroupfsPath) + continue } + podUID := parts[1] + foundPods[types.UID(podUID)] = internalPath } } } diff --git a/pkg/kubelet/kubelet_pods.go b/pkg/kubelet/kubelet_pods.go index cf3a0a839149d..392cf39e403f7 100644 --- a/pkg/kubelet/kubelet_pods.go +++ b/pkg/kubelet/kubelet_pods.go @@ -1557,7 +1557,7 @@ func (kl *Kubelet) cleanupOrphanedPodCgroups( // If volumes have not been unmounted/detached, do not delete the cgroup in case so the charge does not go to the parent. if podVolumesExist := kl.podVolumesExist(uid); podVolumesExist { - glog.V(3).Infof("Orphaned pod %q found, but volumes are not cleaned up, Skipping cgroups deletion: %v", uid) + glog.V(3).Infof("Orphaned pod %q found, but volumes are not cleaned up, Skipping cgroups deletion.", uid) continue } glog.V(3).Infof("Orphaned pod %q found, removing pod cgroups", uid)