Commit a7684569 authored by Derek Carr's avatar Derek Carr Committed by Vishnu kannan

Fix get all pods from cgroups logic

parent b8688295
...@@ -147,6 +147,7 @@ func (l *libcontainerAdapter) revertName(name string) CgroupName { ...@@ -147,6 +147,7 @@ func (l *libcontainerAdapter) revertName(name string) CgroupName {
panic(err) panic(err)
} }
driverName = strings.TrimSuffix(driverName, ".slice") driverName = strings.TrimSuffix(driverName, ".slice")
driverName = strings.Replace(driverName, "-", "/", -1)
driverName = strings.Replace(driverName, "_", "-", -1) driverName = strings.Replace(driverName, "_", "-", -1)
return CgroupName(driverName) return CgroupName(driverName)
} }
......
...@@ -200,24 +200,31 @@ func (m *podContainerManagerImpl) GetAllPodsFromCgroups() (map[types.UID]CgroupN ...@@ -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) return nil, fmt.Errorf("failed to read the cgroup directory %v : %v", qc, err)
} }
for i := range dirInfo { for i := range dirInfo {
// note: we do a contains check because on systemd, the literal cgroupfs name will prefix the qos as well. // its not a directory, so continue on...
if dirInfo[i].IsDir() && strings.Contains(dirInfo[i].Name(), podCgroupNamePrefix) { if !dirInfo[i].IsDir() {
// we need to convert the name to an internal identifier continue
internalName := m.cgroupManager.CgroupName(dirInfo[i].Name()) }
// we then split the name on the pod prefix to determine the uid // convert the concrete cgroupfs name back to an internal identifier
parts := strings.Split(string(internalName), podCgroupNamePrefix) // this is needed to handle path conversion for systemd environments.
// the uid is missing, so we log the unexpected cgroup not of form pod<uid> // we pass the fully qualified path so decoding can work as expected
if len(parts) != 2 { // since systemd encodes the path in each segment.
location := path.Join(qc, dirInfo[i].Name()) cgroupfsPath := path.Join(qcConversion, dirInfo[i].Name())
glog.Errorf("pod cgroup manager ignoring unexpected cgroup %v because it is not a pod", location) internalPath := m.cgroupManager.CgroupName(cgroupfsPath)
continue // 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.
podUID := parts[1] basePath := path.Base(string(internalPath))
// because the literal cgroupfs name could encode the qos tier (on systemd), we avoid double encoding if !strings.Contains(basePath, podCgroupNamePrefix) {
// by just rebuilding the fully qualified CgroupName according to our internal convention. continue
cgroupName := CgroupName(path.Join(qosContainerName, podCgroupNamePrefix+podUID)) }
foundPods[types.UID(podUID)] = cgroupName // 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<uid>
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
} }
} }
} }
......
...@@ -1533,7 +1533,7 @@ func (kl *Kubelet) cleanupOrphanedPodCgroups( ...@@ -1533,7 +1533,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 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 { 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 continue
} }
glog.V(3).Infof("Orphaned pod %q found, removing pod cgroups", uid) glog.V(3).Infof("Orphaned pod %q found, removing pod cgroups", uid)
......
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