mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
kubelet/dockertool: Move Getpods() to DockerManager.
This commit is contained in:
@@ -562,53 +562,3 @@ func GetKubeletDockerContainers(client DockerInterface, allContainers bool) (Doc
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// TODO: Move this function with dockerCache to DockerManager.
|
||||
func GetPods(client DockerInterface, all bool) ([]*kubecontainer.Pod, error) {
|
||||
pods := make(map[types.UID]*kubecontainer.Pod)
|
||||
var result []*kubecontainer.Pod
|
||||
|
||||
containers, err := GetKubeletDockerContainers(client, all)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Group containers by pod.
|
||||
for _, c := range containers {
|
||||
if len(c.Names) == 0 {
|
||||
glog.Warningf("Cannot parse empty docker container name: %#v", c.Names)
|
||||
continue
|
||||
}
|
||||
dockerName, hash, err := ParseDockerName(c.Names[0])
|
||||
if err != nil {
|
||||
glog.Warningf("Parse docker container name %q error: %v", c.Names[0], err)
|
||||
continue
|
||||
}
|
||||
pod, found := pods[dockerName.PodUID]
|
||||
if !found {
|
||||
name, namespace, err := kubecontainer.ParsePodFullName(dockerName.PodFullName)
|
||||
if err != nil {
|
||||
glog.Warningf("Parse pod full name %q error: %v", dockerName.PodFullName, err)
|
||||
continue
|
||||
}
|
||||
pod = &kubecontainer.Pod{
|
||||
ID: dockerName.PodUID,
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
}
|
||||
pods[dockerName.PodUID] = pod
|
||||
}
|
||||
pod.Containers = append(pod.Containers, &kubecontainer.Container{
|
||||
ID: types.UID(c.ID),
|
||||
Name: dockerName.ContainerName,
|
||||
Hash: hash,
|
||||
Created: c.Created,
|
||||
})
|
||||
}
|
||||
|
||||
// Convert map to list.
|
||||
for _, c := range pods {
|
||||
result = append(result, c)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user